[python-win32] NT service

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Nov 10 15:24:55 CET 2004


[walou]

| Thanks, it's the vocabulary that misses to me. I've walking through 
| the article and came to the conclusion that I better have to use 
| dll interaction with winlogon.exe and to send a signal to the NT service.
| I'm now looking for a way to write such a dll in python so if someone
| has any idea ... even just tell me if it's possible ...

Strictly, you can't write a DLL in Python. If you were up to it,
you could write a DLL in C (or whatever), catch the winlogon
notifications, and then -- somehow -- notify your service.
My advice stops there, because it's *years* since I had to
write a DLL, and I've pretty much forgotten how.

The WMI route is a possibility, however. It's a bit tricky
to test because it has to run in a service (always painful
to debug) but something like the following might serve:

<code>

import wmi
c = wmi.WMI ()
watcher = c.watch_for (
  notification_type="Creation",
  wmi_class = "Win32_LogonSession"
)
while 1:
  logon_event = watcher ()
  print logon_event

</code>

I've tested this (without cutting-and-pasting) on someone
else's XP box by doing a RunAs to simulate someone's logging
in and it seems to work. What I can't immediately see is how
you go about working out *who* has logged in. I imagine that
you can use the Win32_LogonSession's LogonId to interrogate
some list of logons. But I'm afraid I don't have time to
check at the moment.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list