how to get the NT event log properties with OnObjectReady() with python

H

hainguyen2x

I'm trying to get a notification from the NT event for any new event
using the DispatchWithEvents() function. Everything seems to be
working the way I wanted, but I don't know how to get the properties
of the event (ie. event type, message, etc.) from the OnObjectReady()
callback.

class SinkClass(object):
def OnObjectReady(self, *args): #self may be the wmi_sink object
print "OnObjectReady callback ..."
print self #.TargetInstance.Message
print args[0]

def OnCompleted(self, *args):
print "OnCompleted callback..."
print args #.TargetInstance.Message

def OnObjectPut(self, *args):
print "OnObjectPut callback..."

def OnProgress(self, *args):
print "OnProgress callback..."

wmi = win32com.client.GetObject("winmgmts:
{impersonationLevel=impersonate,(security)}!//./root/cimv2")
wmi_sink =
win32com.client.DispatchWithEvents("WbemScripting.SWbemSink",SinkClass)
wmi.ExecNotificationQueryAsync(wmi_sink,"SELECT * FROM
__InstanceCreationEvent where TargetInstance ISA 'Win32_NTLogEvent'")


The argument args in the OnObjectReady() seems to be the interface to
a com object (may be the event object itself).
I want to read the properties (ie. message, eventID, type, etc) of
the triggered NT event.

Please help.
 
R

Roger Upole

I'm trying to get a notification from the NT event for any new event
using the DispatchWithEvents() function. Everything seems to be
working the way I wanted, but I don't know how to get the properties
of the event (ie. event type, message, etc.) from the OnObjectReady()
callback.

class SinkClass(object):
def OnObjectReady(self, *args): #self may be the wmi_sink object
print "OnObjectReady callback ..."
print self #.TargetInstance.Message
print args[0]

def OnCompleted(self, *args):
print "OnCompleted callback..."
print args #.TargetInstance.Message

def OnObjectPut(self, *args):
print "OnObjectPut callback..."

def OnProgress(self, *args):
print "OnProgress callback..."

wmi = win32com.client.GetObject("winmgmts:
{impersonationLevel=impersonate,(security)}!//./root/cimv2")
wmi_sink =
win32com.client.DispatchWithEvents("WbemScripting.SWbemSink",SinkClass)
wmi.ExecNotificationQueryAsync(wmi_sink,"SELECT * FROM
__InstanceCreationEvent where TargetInstance ISA 'Win32_NTLogEvent'")


The argument args in the OnObjectReady() seems to be the interface to
a com object (may be the event object itself).
I want to read the properties (ie. message, eventID, type, etc) of
the triggered NT event.

Please help.

The first arg is passed as a raw IDispatch interface. You can wrap it
as below to access the properties.

def OnObjectReady(self, *args): #self may be the wmi_sink object
print "OnObjectReady callback ..."
print self #.TargetInstance.Message
wbem_object=win32com.client.gencache.EnsureDispatch(args[0],0)
print wbem_object
ti=wbem_object.Properties_('TargetInstance').Value
print 'TargetInstance',ti
for p in ti.Properties_:
print p.Name, p.Value


Roger
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top