473,394 Members | 1,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3314
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
8
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my...
3
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
5
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
This code works fine in Windows Application. In Windows Application, I am able to zip the image files properly and it totally contains 900MB My problem is the same code which I used in my Windows...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: Overview NOTE- This complete article on "Windows Autorun FAQs" applies theoretically to all Windows NT-based OSes till Windows Vista (and probably Vista's successors too)....
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.