[python-win32] Windows services in python

Tim Roberts timr at probo.com
Fri Aug 31 20:45:12 CEST 2007


Dmitry Alekseenko wrote:
> Hey guys,
>
> I've written the following function to enable/disable windows services:
>
> def Enable(self, serviceName, enable, autoStart=False):
>     startType = None
>     if not enable:
>         startType = win32service.SERVICE_DISABLED
>     elif autoStart:
>         startType = win32service.SERVICE_AUTO_START
>     else:
>         startType = win32service.SERVICE_DEMAND_START
>     win32serviceutil.ChangeServiceConfig(None, serviceName, startType)
>
> And it turns out that when I call Enable('W32Time', False) it corrupts
> the "path to executable" property of the service. It replaces the path
> to "C:\Python24\lib\site-packages\win32\PythonService.exe".
>
> What wrong am I doing?

win32serviceutil.ChangeServiceConfig is a wrapper around the service
management APIs, designed specifically for managing Python services. 
When you omit the exeName parameter, it assumes you want the generic
Python service wrapper, and looks up the name.

I suggest you skip the win32serviceutil wrapper altogether and call
win32service.ChangeServiceConfig.  That is a much more direct wrapper
around the Win32 API.  You will have to open the service manager
yourself, but you can look at the source for win32serviceutil.py to see
how to do that.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list