I’m trying to read data from the WMI Win32_NTLogEvent class, but I only want to read instances where TimeWritten falls within a date range.
I’m using the WMI module for Python which allows for a pure WMI Query(1) or a parameterized approach(2):
-
c.query("Select SourceName, Message from Win32_NTLogEvent where EventType =1, Logfile = \"Application\"") -
c.Win32_NTLogEvent(EventType =1, Logfile = "Application")
The problem is, I can’t seem to get either to accept my date arguments. I’ve tried several date formats including the rather obscure WMI style, and my only success was using the 2nd approach above with the = operator, which doesn’t really help:
c.Win32_NTLogEvent(EventType =1, Logfile = "Application", TimeWritten = "20110421013749.000000-000")
I know I could filter the result set in my Python code, but I’m fairly certain this can be done in the query. I guess I’m just missing something. Anyone have suggestions?
Thanks.
your WQL sentence is wrong
Replace this code
by this one
Note : I don’t know much about python (but i know a couple of things about the WMI), so maybe you must escape the special chars in another way.