windows services

F

Francis Lavoie

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
 
P

Peter L Hansen

Francis said:
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.

This is initially a non-Python question, because you will need
to identify how you would do that using the Windows API. Once
you've answered that question (searching MSDN usually helps)
you can try a Google (or Google Groups) search for the name
of the API function along with "python", and usually that will
point you to where someone else has already done it.

If Google doesn't help you at that point, posting here with the
relevant Windows-specific info will generally get you a response
using pywin32 or ctypes that will do the job.

-Peter
 
V

vincent wehren

Francis said:
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
Mybe this helps:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59872
 
M

Michael Loritsch

Francis Lavoie said:
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
 
E

Elbert Lev

Francis Lavoie said:
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

I assume that you have "Python for Win32 Extensions" installed and you
are running your script not on linux computer :). To cntrol servicea
(including pause, stop etc.) one should use
win32service.ControlService(scHandle, code ).
code = 1 (from c include:
#define SERVICE_CONTROL_STOP 0x00000001
)
then you call win32service.StartService(scHandle, args)

Local/remote is controlled by

OpenSCManager(machineName, dbName , desiredAccess )

machineName - does the trik!

Good luck!
 
F

Francis Lavoie

vincent said:

Ok thank, that's working perfectly.
I also tried Michael Loritsch and Elbert Lev suggestion(win32service),
but that failed for some module, telling 'The specified service does not
exist as an installed service.'.
But win32serviceutil work perfectly. It is only undocument in the
pywin32 documentation but I think I'll have to search on google for
further information.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top