[python-win32] wmi.py + pythonservice.exe

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri May 7 02:30:41 EDT 2004


> using - win2k, python2.3.3, pywin32 201.1, wmi 0.5 (from Tim Golden)
>
> I've successfully implemented some pieces of code using Tim 
> Golden's wmi module and they work well.  

Glad to hear it!

>When I take working service code, add an "import wmi" statement, and 
>update the service, I then suddenly get failures when trying 
>to start the service.  The event log holds almost no information.  

No magic bullet here, I'm afraid. I've not tried this myself, tho'
if I have time this morning I'll give it a go.
You're up against at least two things:

+ Security issues around services, which -- by default -- run
  as the most basic user possible, without network access (I
  think).

+ The WMI security model is a real pain to manipulate, not
  least because you have to contend with its own security,
  general COM / DCOM security, and even more general NT
  Security, all of which are interlinked, but subtly different
  (or at least that's the impression I have from no small
  amount of research).

And, of course, it may be that even sorting this out won't 
solve your problem!

I suggest that you run the service under the same user which
you're logged in as. In case you haven't done this before, it
means going to Control Panel -> Admin Tools -> Services
(or however you normally get there), right-clicking for 
Properties, selecting the LogOn tab, and specifying an
exact account. Then try starting the service again.

As you can see from the top of the WMI file, the only thing
the module does on import (apart from defining a few constants
and, obviously, the classes and functions) is to call 
win32com.client.gencache.EnsureDispatch. This is to ensure
that various constants etc are readily available. There aren't
many, (in fact, three), so you might try adding these lines 
somewhere towards the top of the module at line 129:

wbemErrInvalidQuery = -2147217385
wbemErrTimedout = -2147209215

  to replace lines 129-131:

#obj = win32com.client.GetObject ("winmgmts:")
#win32com.client.gencache.EnsureDispatch (obj._oleobj_)
#del obj

You could then replace "win32com.client.constants." with ""
throughout (there are only three instances) and see if that
helps.

(In case it wasn't obvious, all I'm doing there is to remove
the need to do any win32com stuff on module import, in case
that's a problem.)

Let us know if that helps or hinders.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. 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