service windows avec py2exe

Tim Golden tjgolden at
Sun Nov 12 15:35:57 CET 2006

DarkPearl wrote:
> ok,
> It's this line who crash the service :
> self.WMIService
> =win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
> why this function goes when it is not a service?
> with IDLE -> ok
> with py2exe executable (no windows service) -> ok
> with py2exe service option true (windows service) -> CRASH....

OK. I think I can help here. WMI is a COM/DCOM-based technology.
Windows services are inherently multithreaded. Therefore you need to
Initialize a COM threading model specifically even though you're not
really using threads yourself.

Try putting:

import pythoncom
pythoncom.CoInitialize ()

somewhere before the line which instantiates the WMI
object (the one you quoted above).

I have no idea why this usually manifests itself as a
"Syntax Error" but it does!


More information about the Python-list mailing list