RE: Getting eventlogs in last 24 hours
"Oliver Marshall" wrote:
> Hi,
>
> I have a script that returns the eventlogs that have occurred on a specified
> day. However, i have a need to mod the script so that it returns the logs
> that have occurred within the last 24 hours (this being different to on a
> specified day). ie if it runs at 07:30 monday it should return logs between
> 07:30 sunday and 07:30 monday.
>
> How should I phrase the SQL for this ? Currently I have...
>
> Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
> Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
> DateToCheck = CDate("9/24/2007")
> dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
> dtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME
>
> ...
>
> Set colEvents = objWMIService.ExecQuery _
> ("Select * from Win32_NTLogEvent Where Logfile = 'Application' and
> TimeWritten >= '" & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'
> and Type='Error'")
>
> ...
>
You can try setting DateToCheck to Now() and use DateToCheck - 1 (Didn't
test this):
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Now
dtmStartDate.SetVarDate DateToCheck - 1, CONVERT_TO_LOCAL_TIME
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and
TimeWritten >= '" & dtmStartDate & "' and Type='Error'")
--
urkec
|