PC Review Forums Newsgroups Windows XP Windows XP WMI Event Log Error

Reply

Event Log Error

 
Thread Tools Rate Thread
Old 14-03-2007, 09:11 PM   #1
de Graff
Guest
 
Posts: n/a
Default Event Log Error


I built all of our servers with the same Windows Server 2003 CD and (I
believe) I have set them up with the same options. Does anyone know why the
following query from a remote machine works on some servers and not on
others? The error disappears when I remove the TimeWritten portion of the
query. The error I get indicates an invalid query (syntax).

Select * from Win32_NTLogEvent Where Logfile = 'Application' and SourceName
= 'LiveState Recovery' and TimeWritten >= '2007-03-11' and TimeWritten <=
'2007-03-11 23:59:59'


  Reply With Quote
Old 16-03-2007, 03:32 PM   #2
de Graff
Guest
 
Posts: n/a
Default Re: Event Log Error

OK. I found the problem. Some servers (but not others for some strange
reason) require that the TimeWritten query reference th SWbemDateTime helper
object. So the correct query becomes

set lower = CreateObject("WbemScripting.SWbemDateTime")
set upper = CreateObject("WbemScripting.SWbemDateTime")

lower.SetVarDate Date-offset,true
upper.SetVarDate Date-offset+1,true

Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & server
& "\root\cimv2")
query = "Select * from Win32_NTLogEvent" _
& " Where Logfile = 'Application'" _
& " and SourceName = 'LiveState Recovery'" _
& " and TimeWritten >= '" & lower & "'" _
& " and TimeWritten < '" & upper & "'"
Set events = wmi.ExecQuery(query)

with offset set to an integer (1=yesterday)


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off