471,330 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

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

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.

Oct 11 '07 #1
1 2905

<ha*********@yahoo.comwrote in message news:11*********************@22g2000hsm.googlegrou ps.com...
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.EnsureDispatc h(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


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Oct 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Eric | last post: by
18 posts views Thread by Christopher W. Douglas | last post: by
4 posts views Thread by Pai | last post: by
4 posts views Thread by Varghjärta | last post: by
17 posts views Thread by dan_williams | last post: by
6 posts views Thread by manstey | last post: by
17 posts views Thread by David C. Ullrich | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.