Francis Lavoie <fr******@aei.c a> wrote in message news:<ma******* *************** *************** *@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.Op enSCManager
2) Obtain a handle the service you wish to stop -> use
win32service.Op enService
3) Tell the service to stop -> use win32service.Co ntrolService with
the proper control code for stopping a service.
4) Start the service -> use win32service.St artService
Regards,
Michael Loritsch