473,657 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3328
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.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
Jul 18 '05 #4
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


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.Co ntrolService(sc Handle, code ).
code = 1 (from c include:
#define SERVICE_CONTROL _STOP 0x00000001
)
then you call win32service.St artService(scHa ndle, args)

Local/remote is controlled by

OpenSCManager(m achineName, 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(win3 2service),
but that failed for some module, telling 'The specified service does not
exist as an installed service.'.
But win32serviceuti l 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
2884
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
4183
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 send mail code is executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services registry DependOnService value including SMPTSVC and...
3
6133
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 for the application doesn't appear - however, I can see the process in the TaskManager. Now, feel free to mention that starting a regular windows application
5
2291
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 Application, does not work while I run it with Windows services. In my Windows application I am able to zip the whole 900Mb without any problems, but in my windows services I am not able to zip the whole 900Mb. In Windows Services it throws an...
2
4483
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 seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
1
4843
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 seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
5
3296
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? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
6116
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). Much of the contents of this article are tested on Windows XP professional SP2 by the author. Some instances of this article may be altogether different/missing on Windows Vista, XP and other Windows NT systems, but I have tried to write a...
0
30207
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 a comprehensive list of all autostart locations for Windows OSes: NOTE : These are some abbreviations used in this list. Please note them carefully: HKCU = HKEY_CURRENT_USER HKLM = HKEY_LOCAL_MACHINE
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8502
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.