| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have spent ages trying to get this to work but It has got the best of me can anybody point out the obvious please.
My plan is to have an email sent to me via smartmail with the results. Set objArgs = WScript.Arguments Const ForReading = 1 Set objDictionary = CreateObject("Scripting.Dictionary") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("serverlist.txt", ForReading) Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime") Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime") DateToCheck = Date - 1 dtmEndDate.SetVarDate Date, True dtmStartDate.SetVarDate DateToCheck, True i = 0 Do While objTextFile.AtEndOfStream <> True strNextLine = objTextFile.Readline objDictionary.Add i, strNextLine i = i + 1 Loop For Each objitem in objDictionary Set colServices = GetObject("winmgmts://" & objDictionary.Item(objItem) _ & "").ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _ & "EventCode = '208' and " _ & TimeWritten >= '" _ & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'") For Each objEvent in colServices Wscript.Echo "Category: " & objEvent.Category Wscript.Echo "Computer Name: " & objEvent.ComputerName Wscript.Echo "Event Code: " & objEvent.EventCode Wscript.Echo "Message: " & objEvent.Message Wscript.Echo "Record Number: " & objEvent.RecordNumber Wscript.Echo "Source Name: " & objEvent.SourceName Wscript.Echo "Time Written: " & objEvent.TimeWritten Wscript.Echo "Event Type: " & objEvent.Type Wscript.Echo "User: " & objEvent.User Next |
|
#2
|
||||
|
||||
|
I noticed you use set objArgs but I don't see where you ever use it?
Anyway, you have two For Each statements and ONE Next To make your select more readable you can first put the SELECT statement in a varialbe and then use the variable in the Set statement. It's too hard to keep track of all of your line continuations, easy to miss a quote somewhere and you won't know it if you are simply running this as a script file. stmnt = "Select * from Win32_NTLogEvent Where Logfile = 'Application' and EventCode = '208' and TimeWritten >= '" & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'" Set colServices = GetObject("winmgmts://" & objDictionary.Item(objItem)).ExecQuery(stmnt) You can use MS Access as a debug tool: Open database module, create private sub, paste the above code into it (between the "Privat Sub mysub()" and "End Sub", then goto tools, references and checkmark "Microsoft Scripting Runtime" You will have to make some slight modifications (comment out straight script like Date - 1 and replace with a dateadd("d",1,date), but it only takes a few minutes to provide the alternative syntax to the point where Access will tell you that you are mising something like a Next statement. Plus you can put a break point in there and step through your code. You can use SQL Server DTS to test scripts: Create a new Data Transformation Package. Click on ActiveX Script. Open it and past your code in. You cannot debug with breakpoints but it does understand straight script like Date-1. YOu can systematically comment out blocks of code and place strategic mesage boxes to help you debug. msgbox = strNextLine either way You can force values into variables such as strNextLine = some deliberate value i=0 objDictionary.Add i, strNextLine i=i+1 stNextLine = some other deliberte value objDictionary.Add i Is the objDictinariy getting updated?? msgbox objDictionary(some property) If you don't know what properties are avaialbe, place a breakpoint in Access on the first line, step the code until you have opened the object - comment out erroring code if you need to as long as you can still get the object to open (or just drag your yellow highlight to the step you want) - then open the Locals window. what do you see? your object is on the list with current values. You can check the state of everything at any moment in time. You can browse properties. Well worth the hassle of converting it back from VBA to script if you ask me! Or just leave your script in Access and let it run the finished script as VBA using the microsfot scripting library described above. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Frustrated |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|