[python-win32] wmi and NT service

walou c.walou at laposte.net
Mon Nov 22 17:30:10 CET 2004


It was just a ms-joke, because the service is launched by SYSTEM
account, so the service tried to import %WINDIR%\Sytem32\wmi.dll ....
renaming wmi.py to pywmi.py solved the problem

But you know, with me, a solved problem always produces a new question
and "here I am" :
How can I get the name of the currently logged on user in a NT service ?
os.environ['USERNAME'] don't work ... (hooooooo )

Klaas


Le lun 22/11/2004 à 16:11, walou a écrit :
> Hello,
> While I was crawling python.org I found :
> 
> """c = wmi.WMI()
> event_watcher=c.watch_for
> (notification_type="Creation",wmi_class="Win32_NTLogEvent",delay_secs=1)
> 
> <while service is running>
> evt=event_watcher()
> <code to examine event, raise flag if detect RAID event>"""
> 
> I want to know any changes in Win32_Session in a NT service. So I tried :
> 
> ...
> def SvcDoRun(self):
>     import wmi
>     c = wmi.WMI()
>     event_watcher=c.watch_for(notification_type="Creation",wmi_class="Win32_Session",delay_secs=1)
>     evt = event_watcher()
>     fh = file('c:\montest.log','w')
>     fh.write('coucou')
>     fh.close
> ...
> 
> Just pasted in a .py file, it works fine (I tested it by installing IIS FTP Server and opening sessions on it, note that if you want to retest, you have to use an other login)
> The entire code of the service comes from another which works fine, I just replace a few lines with the ones I wrote above.
> The service don't start anymore ... does somebody see why ?
> 
> 
> Klaas
> 
> 
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



More information about the Python-win32 mailing list