From: News123 on
Just having a short question:

I found a code snippet, that fetches windows event logs via a wmi query.

import win32com.client

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_NTLogEvent")

for i,itm in enumerate(colItems):
entry =( itm.TimeGenerated,itm.TimeWritten,
itm.Category,itm.CategoryString,itm.ComputerName,
itm.Data,itm.EventCode,itm.EventIdentifier,
itm.EventType,itm.InsertionStrings,itm.LogFile,
itm.Message,itm.RecordNumber,
itm.SourceName,itm.Type,itm.User)
print entry

Asumming I would not have no documentation, I would be too lazy to
lookup or to type all this code.

Would there be any way to query the list of members
( TimeGenerated , TimeWritten, . . . ) of variable itm?


thanks upfront



N
From: Tim Golden on
On 16/04/2010 01:39, News123 wrote:
> Just having a short question:
>
> I found a code snippet, that fetches windows event logs via a wmi query.
>
> import win32com.client
>
> strComputer = "."
> objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
> objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
> colItems = objSWbemServices.ExecQuery("Select * from Win32_NTLogEvent")
>
> for i,itm in enumerate(colItems):
> entry =( itm.TimeGenerated,itm.TimeWritten,
> itm.Category,itm.CategoryString,itm.ComputerName,
> itm.Data,itm.EventCode,itm.EventIdentifier,
> itm.EventType,itm.InsertionStrings,itm.LogFile,
> itm.Message,itm.RecordNumber,
> itm.SourceName,itm.Type,itm.User)
> print entry
>
> Asumming I would not have no documentation, I would be too lazy to
> lookup or to type all this code.
>
> Would there be any way to query the list of members
> ( TimeGenerated , TimeWritten, . . . ) of variable itm?

Look at the object's .Properties_ attribute, eg:

print [p.Name for p in itm.Properties_]

TJG