Prev: how to catch error: cant open ADODB connection
Next: VBS and CDO.Message / Mapi.Session - which should I use
From: ekrengel on 9 Jun 2010 12:31 Ok, so I'm working on querying multiple DC's to look for a specific event ID (645 in the security logs, for computers recently joined to the domain). I thought I had everything figured out, but it's still not working right. Running the script, it just somewhat hangs...not sure if that's just because it's still searching or not and is slow. Let me know if you guys have any thoughts...thanks! Dim objDictionary Set objDictionary = CreateObject("Scripting.Dictionary") arrComputers = Array("DC02", "DC03") iReach = 0 For Each strComputer in arrComputers Connect strComputer Next If (iReach = 0) Then WScript.Echo "No Computers were reachable!" WScript.Quit End If colKeys = objDictionary.Keys If (colKeys.Count = 0) Then WScript.Echo "No events were found!" WScript.Quit End If For Each strKey in colKeys WScript.Echo strKey Next WScript.Quit Sub Connect(sComputer) On Error Resume Next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & sComputer & "\root \cimv2") If (Err.Number <> 0) Then On Error GoTo 0 WScript.echo "Could not connect to " & sComputer Exit Sub End If On Error GoTo 0 iReach = iReach + 1 Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND (EventCode = 645)") ' 645 = Computer joined to domain For Each objEvent in colLoggedEvents strEventCode = objEvent.EventCode srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) objDictionary.Add strEventCode, strMessage Next End Sub
From: ekrengel on 14 Jun 2010 10:52 On Jun 9, 12:31 pm, ekrengel <erickreng...(a)gmail.com> wrote: > Ok, so I'm working on querying multiple DC's to look for a specific > event ID (645 in the security logs, for computers recently joined to > the domain). I thought I had everything figured out, but it's still > not working right. Running the script, it just somewhat hangs...not > sure if that's just because it's still searching or not and is slow. > > Let me know if you guys have any thoughts...thanks! > > Dim objDictionary > > Set objDictionary = CreateObject("Scripting.Dictionary") > > arrComputers = Array("DC02", "DC03") > iReach = 0 > > For Each strComputer in arrComputers > Connect strComputer > Next > > If (iReach = 0) Then > WScript.Echo "No Computers were reachable!" > WScript.Quit > End If > > colKeys = objDictionary.Keys > > If (colKeys.Count = 0) Then > WScript.Echo "No events were found!" > WScript.Quit > End If > > For Each strKey in colKeys > WScript.Echo strKey > Next > > WScript.Quit > > Sub Connect(sComputer) > On Error Resume Next > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & sComputer & "\root > \cimv2") > If (Err.Number <> 0) Then > On Error GoTo 0 > WScript.echo "Could not connect to " & sComputer > Exit Sub > End If > On Error GoTo 0 > > iReach = iReach + 1 > > Set colLoggedEvents = objWMIService.ExecQuery _ > ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND > (EventCode = 645)") > ' 645 = Computer joined to domain > > For Each objEvent in colLoggedEvents > strEventCode = objEvent.EventCode > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > objDictionary.Add strEventCode, strMessage > Next > End Sub The issue is definitely with the "for" statement in the sub. I went through some debugging and found the script hangs there. It doesn't make it past the first "For Each" line. I still don't know what's wrong with this statement though, or what's causing it to hang. For Each objEvent in colLoggedEvents wscript.echo "got past for statement" wscript.quit strEventCode = objEvent.EventCode srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) objDictionary.Add strEventCode, strMessage Next
From: ekrengel on 14 Jun 2010 12:06 On Jun 14, 10:52 am, ekrengel <erickreng...(a)gmail.com> wrote: > On Jun 9, 12:31 pm, ekrengel <erickreng...(a)gmail.com> wrote: > > > > > Ok, so I'm working on querying multiple DC's to look for a specific > > event ID (645 in the security logs, for computers recently joined to > > the domain). I thought I had everything figured out, but it's still > > not working right. Running the script, it just somewhat hangs...not > > sure if that's just because it's still searching or not and is slow. > > > Let me know if you guys have any thoughts...thanks! > > > Dim objDictionary > > > Set objDictionary = CreateObject("Scripting.Dictionary") > > > arrComputers = Array("DC02", "DC03") > > iReach = 0 > > > For Each strComputer in arrComputers > > Connect strComputer > > Next > > > If (iReach = 0) Then > > WScript.Echo "No Computers were reachable!" > > WScript.Quit > > End If > > > colKeys = objDictionary.Keys > > > If (colKeys.Count = 0) Then > > WScript.Echo "No events were found!" > > WScript.Quit > > End If > > > For Each strKey in colKeys > > WScript.Echo strKey > > Next > > > WScript.Quit > > > Sub Connect(sComputer) > > On Error Resume Next > > Set objWMIService = GetObject("winmgmts:" _ > > & "{impersonationLevel=impersonate}!\\" & sComputer & "\root > > \cimv2") > > If (Err.Number <> 0) Then > > On Error GoTo 0 > > WScript.echo "Could not connect to " & sComputer > > Exit Sub > > End If > > On Error GoTo 0 > > > iReach = iReach + 1 > > > Set colLoggedEvents = objWMIService.ExecQuery _ > > ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND > > (EventCode = 645)") > > ' 645 = Computer joined to domain > > > For Each objEvent in colLoggedEvents > > strEventCode = objEvent.EventCode > > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > > objDictionary.Add strEventCode, strMessage > > Next > > End Sub > > The issue is definitely with the "for" statement in the sub. I went > through some debugging and found the script hangs there. It doesn't > make it past the first "For Each" line. I still don't know what's > wrong with this statement though, or what's causing it to hang. > > For Each objEvent in colLoggedEvents > > wscript.echo "got past for statement" > wscript.quit > > strEventCode = objEvent.EventCode > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > objDictionary.Add strEventCode, strMessage > Next So I take what I said back =) It's really just a matter of WMI being slow and me being impatient...it takes a while for it to query the security logs. I made some changes to the script where I had errors: Dim objDictionary Set objDictionary = CreateObject("Scripting.Dictionary") arrComputers = Array("DC02") iReach = 0 For Each strComputer in arrComputers Connect strComputer Next If (iReach = 0) Then WScript.Echo "No Computers were reachable!" WScript.Quit End If strEventCount = objDictionary.Count If (strEventCount = 0) Then WScript.Echo "No events were found!" WScript.Quit End If colKeys = objDictionary.Keys For Each strKey in colKeys WScript.Echo strKey Next WScript.Quit Sub Connect(sComputer) On Error Resume Next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Security)}!\\" _ & sComputer & "\root\cimv2") If (Err.Number <> 0) Then On Error GoTo 0 WScript.echo "Could not connect to " & sComputer Exit Sub End If On Error GoTo 0 iReach = iReach + 1 Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND EventCode = '645'",,48) For Each objEvent in colLoggedEvents strEventCode = objEvent.EventCode srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) objDictionary.Add strEventCode, strMessage Next End Sub
From: BigDaddyJim on 15 Jun 2010 07:43 On Jun 14, 11:06 am, ekrengel <erickreng...(a)gmail.com> wrote: > On Jun 14, 10:52 am, ekrengel <erickreng...(a)gmail.com> wrote: > > > > > > > On Jun 9, 12:31 pm, ekrengel <erickreng...(a)gmail.com> wrote: > > > > Ok, so I'm working on querying multiple DC's to look for a specific > > > event ID (645 in the security logs, for computers recently joined to > > > the domain). I thought I had everything figured out, but it's still > > > not working right. Running the script, it just somewhat hangs...not > > > sure if that's just because it's still searching or not and is slow. > > > > Let me know if you guys have any thoughts...thanks! > > > > Dim objDictionary > > > > Set objDictionary = CreateObject("Scripting.Dictionary") > > > > arrComputers = Array("DC02", "DC03") > > > iReach = 0 > > > > For Each strComputer in arrComputers > > > Connect strComputer > > > Next > > > > If (iReach = 0) Then > > > WScript.Echo "No Computers were reachable!" > > > WScript.Quit > > > End If > > > > colKeys = objDictionary.Keys > > > > If (colKeys.Count = 0) Then > > > WScript.Echo "No events were found!" > > > WScript.Quit > > > End If > > > > For Each strKey in colKeys > > > WScript.Echo strKey > > > Next > > > > WScript.Quit > > > > Sub Connect(sComputer) > > > On Error Resume Next > > > Set objWMIService = GetObject("winmgmts:" _ > > > & "{impersonationLevel=impersonate}!\\" & sComputer & "\root > > > \cimv2") > > > If (Err.Number <> 0) Then > > > On Error GoTo 0 > > > WScript.echo "Could not connect to " & sComputer > > > Exit Sub > > > End If > > > On Error GoTo 0 > > > > iReach = iReach + 1 > > > > Set colLoggedEvents = objWMIService.ExecQuery _ > > > ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND > > > (EventCode = 645)") > > > ' 645 = Computer joined to domain > > > > For Each objEvent in colLoggedEvents > > > strEventCode = objEvent.EventCode > > > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > > > objDictionary.Add strEventCode, strMessage > > > Next > > > End Sub > > > The issue is definitely with the "for" statement in the sub. I went > > through some debugging and found the script hangs there. It doesn't > > make it past the first "For Each" line. I still don't know what's > > wrong with this statement though, or what's causing it to hang. > > > For Each objEvent in colLoggedEvents > > > wscript.echo "got past for statement" > > wscript.quit > > > strEventCode = objEvent.EventCode > > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > > objDictionary.Add strEventCode, strMessage > > Next > > So I take what I said back =) > > It's really just a matter of WMI being slow and me being > impatient...it takes a while for it to query the security logs. I > made some changes to the script where I had errors: > > Dim objDictionary > > Set objDictionary = CreateObject("Scripting.Dictionary") > > arrComputers = Array("DC02") > iReach = 0 > > For Each strComputer in arrComputers > Connect strComputer > Next > > If (iReach = 0) Then > WScript.Echo "No Computers were reachable!" > WScript.Quit > End If > > strEventCount = objDictionary.Count > If (strEventCount = 0) Then > WScript.Echo "No events were found!" > WScript.Quit > End If > > colKeys = objDictionary.Keys > For Each strKey in colKeys > WScript.Echo strKey > Next > > WScript.Quit > > Sub Connect(sComputer) > On Error Resume Next > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate,(Security)}!\\" _ > & sComputer & "\root\cimv2") > > If (Err.Number <> 0) Then > On Error GoTo 0 > WScript.echo "Could not connect to " & sComputer > Exit Sub > End If > On Error GoTo 0 > > iReach = iReach + 1 > > Set colLoggedEvents = objWMIService.ExecQuery _ > ("Select * From Win32_NTLogEvent Where Logfile = 'Security' AND > EventCode = '645'",,48) > > For Each objEvent in colLoggedEvents > strEventCode = objEvent.EventCode > srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) > objDictionary.Add strEventCode, strMessage > Next > End Sub- Hide quoted text - > > - Show quoted text - How about a "On error resume next" at the top? Couldn't hurt to try for purposes of diagnosis. Jim
From: Tom Lavedas on 15 Jun 2010 08:32 On Jun 15, 7:43 am, BigDaddyJim <hungerfo...(a)gmail.com> wrote: > > How about a "On error resume next" at the top? Couldn't hurt to try > for purposes of diagnosis. > > Jim I think that's a decidedly LOUSY idea. It can and does hurt to blanket a script with On Error Resume Next (though lots of sample scripts do it). Because it makes troubleshooting HARDER. With it in place, the true source of the problem is generally hidden. Rather, the script tries to 'soldier on', with incorrect intermediate results, often with disastrous results - like corrupting data. It leaves the user to wonder what happened, with likely misleading symptoms of the real problem. The only time it is justified, IMHO, is when a specific bit of code is targeted and specific error handling code is added to test the Err.Number and act accordingly. In that way, the programmer anticipates errors and provides logical workarounds to keep the program on track (or asks the user to make the decision). _____________________ Tom Lavedas
|
Next
|
Last
Pages: 1 2 Prev: how to catch error: cant open ADODB connection Next: VBS and CDO.Message / Mapi.Session - which should I use |