469,287 Members | 2,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

windows services

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

Jul 18 '05 #1
5 2733
Francis Lavoie wrote:
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
Jul 18 '05 #2
Francis Lavoie wrote:
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/Coo...n/Recipe/59872

--
Vincent Wehren
Jul 18 '05 #3
Francis Lavoie <fr******@aei.ca> wrote in message news:<ma**************************************@pyt hon.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
Jul 18 '05 #4
Francis Lavoie <fr******@aei.ca> wrote in message news:<ma**************************************@pyt hon.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


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!
Jul 18 '05 #5
vincent wehren wrote:
Francis Lavoie wrote:
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/Coo...n/Recipe/59872

--
Vincent Wehren


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

Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Bill Sonia | last post: by
5 posts views Thread by =?Utf-8?B?dmlzaHJ1dGg=?= | last post: by
2 posts views Thread by =?Utf-8?B?dmlzaHJ1dGg=?= | last post: by
1 post views Thread by =?Utf-8?B?dmlzaHJ1dGg=?= | last post: by
5 posts views Thread by dm3281 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.