Hi, I hope someone can help me with a script I'm trying to write. I don't know much about vbscript, but I'm trying to piece together a script that will look in a Window 2000 event log, for 1 day and write to a text file when it finds certain events. I get sporatic results with this script. Sometimes it writes the data to the text file ok and other times it doesn't, but I'm getting an error that an object variable is not set and it's pointing to the first Writeline statement. Any ideas anyone?
Thanks.
Dim fso, f1
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\temp\testfile.txt", True)
dtmEndDate = CDate(Date)
dtmStartDate = dtmEndDate - 1
' Converting to WMI "date"
dtmEndDate = Year(dtmEndDate) _
& Right( "00" & Month(dtmEndDate), 2) _
& Right( "00" & Day(dtmEndDate), 2)
dtmStartDate = Year(dtmStartDate) _
& Right( "00" & Month(dtmStartDate), 2) _
& Right( "00" & Day(dtmStartDate), 2)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '1704' and TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For each objEvent in colLoggedEvents
f1.WriteLine "got to here"
f1.WriteLine "Oracle DB shutdowns: " & colLoggedEvents.Count
f1.WriteLine "Message: " & objEvent.Message
f1.WriteLine "Time Written: " & objEvent.TimeWritten
f1.WriteLine "*********"
f1.WriteBlankLines(1)
f1.Close
Next
Thanks.
Dim fso, f1
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\temp\testfile.txt", True)
dtmEndDate = CDate(Date)
dtmStartDate = dtmEndDate - 1
' Converting to WMI "date"
dtmEndDate = Year(dtmEndDate) _
& Right( "00" & Month(dtmEndDate), 2) _
& Right( "00" & Day(dtmEndDate), 2)
dtmStartDate = Year(dtmStartDate) _
& Right( "00" & Month(dtmStartDate), 2) _
& Right( "00" & Day(dtmStartDate), 2)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '1704' and TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For each objEvent in colLoggedEvents
f1.WriteLine "got to here"
f1.WriteLine "Oracle DB shutdowns: " & colLoggedEvents.Count
f1.WriteLine "Message: " & objEvent.Message
f1.WriteLine "Time Written: " & objEvent.TimeWritten
f1.WriteLine "*********"
f1.WriteBlankLines(1)
f1.Close
Next