how to get elements of a com object (wmi log events)

Tim Golden mail at timgolden.me.uk
Fri Apr 16 09:45:28 CEST 2010


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



More information about the Python-list mailing list