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

N

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
 
T

Tim Golden

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

text file 3
Python's win32com.client for Ruby? 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top