windows services
Michael Loritsch
loritsch at gmail.com
Sat Oct 16 20:32:05 EDT 2004
Francis Lavoie <francisl at aei.ca> wrote in message news:<mailman.5046.1097941098.5135.python-list at python.org>...
> Is it possible to restart windows services? (remotely and locally)
>
> Because I have a little script that retreive the LastWaitTimeout key of
> the automatic update, delete that key if it out schedule for our
> production needs. But still the service need to be restarded if I want
> that key to be reset, when Win Update will resynchronize with the sus
> server for new update.
>
> Thankx
Since this is a windows specific question, you must have the windows
extensions installed. I'm assuming you either already have them, or
know where to get them, as that is a different question entirely...
The python module that you need to perform this task is win32service.
In order to restart a service, you should do two things:
1) Tell the service control manager (SCM) to stop the service
2) Then tell the SCM to start the service.
Thus, the pseudocode to restart a service is as follows:
1) Obtain a handle to the SCM -> use win32service.OpenSCManager
2) Obtain a handle the service you wish to stop -> use
win32service.OpenService
3) Tell the service to stop -> use win32service.ControlService with
the proper control code for stopping a service.
4) Start the service -> use win32service.StartService
Regards,
Michael Loritsch
More information about the Python-list
mailing list