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

2010-04-16 Thread Tim Golden

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
--
http://mail.python.org/mailman/listinfo/python-list


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

2010-04-15 Thread News123
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
-- 
http://mail.python.org/mailman/listinfo/python-list