Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching event log for specific entry 1

Status
Not open for further replies.

ACraib

MIS
Sep 7, 2001
579
0
0
GB
Hi

I need to search an event log during the last hour for a specific event ID. Now not being a scripter I've managed to cobble together a script to will search during the last day but I need it to search for during the last hour.

any help will be received with great thanks.

strComputer = "."
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = date
dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and " & "EventCode = '46201' and " & " TimeWritten >= '" & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
 
Perhaps:

Code:
DateToCheck = date + time
'Subtract one hour
dtmStartDate.SetVarDate DateAdd("h",-1,DateToCheck), CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME

 
Works like a charm. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top