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

Roger Upole rupole at hotmail.com
Sat Oct 13 14:56:27 EDT 2007


<hainguyen2x at yahoo.com> wrote in message news:1192120780.301198.62340 at 22g2000hsm.googlegroups.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.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




----== 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 =----



More information about the Python-list mailing list