473,397 Members | 1,960 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,397 software developers and data experts.

trouble with win32serviceutil

I am trying to start and stop a service with python. This used to work on an NT
box but not on this 2003 server machine. (note- using "net stop myService" and
net start myService" from the command line works just fine). The event viewer
does tell me that a "Start command was sent to myService" but the service never
starts.

-------------------------------------------------------------------------

import win32serviceutil

def service_control(service,action,machine='192.168.1. 9'):
if action == 'stop':
try:
win32serviceutil.StopService(service, machine)
return('%s stopped successfully' % service)
except:
return ("Error stopping %s" % (service))
elif action == 'start':
try:
win32serviceutil.StartService(service, machine)
return('%s started successfully' % service)
except:
return ("Error starting %s" % (service))
elif action == 'restart':
try:
win32serviceutil.RestartService(service, machine)
return('%s restarted successfully' % service)
except:
return ("Error restarting %s" % (service))
elif action == 'status':
if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
return("%s is running normally" % service)
else:
return("%s is *not* running" % service)
if __name__ == '__main__':
machine = '192.168.1.9'
service = 'myService'
action = 'start'
print service_control(service,action,machine)
Jul 19 '05 #1
1 5716
Erik Myllymaki wrote:
I am trying to start and stop a service with python. This used to work
on an NT box but not on this 2003 server machine. (note- using "net stop
myService" and net start myService" from the command line works just
fine). The event viewer does tell me that a "Start command was sent to
myService" but the service never starts.

-------------------------------------------------------------------------

import win32serviceutil

def service_control(service,action,machine='192.168.1. 9'):
if action == 'stop':
try:
win32serviceutil.StopService(service, machine)
return('%s stopped successfully' % service)
except:
return ("Error stopping %s" % (service))
elif action == 'start':
try:
win32serviceutil.StartService(service, machine)
return('%s started successfully' % service)
except:
return ("Error starting %s" % (service))
elif action == 'restart':
try:
win32serviceutil.RestartService(service, machine)
return('%s restarted successfully' % service)
except:
return ("Error restarting %s" % (service))
elif action == 'status':
if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
return("%s is running normally" % service)
else:
return("%s is *not* running" % service)
if __name__ == '__main__':
machine = '192.168.1.9'
service = 'myService'
action = 'start'
print service_control(service,action,machine)


Answering my own question - seems to work i you do not specify machine name:

win32serviceutil.StartService(service)

instead of

win32serviceutil.StartService(service, machine)
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: max | last post by:
I am building a service based on win32serviceutil.ServiceFramework. By default it comes out as 'manual start' service. How do I get it to start automatically? thanks, max.
2
by: James | last post by:
Hi I am having some trouble getting a asp page to load. Im a noob to the asp side. I have followed knowledege base Article 301305. I am running 2000 adv, IIS 5.0 I have the following...
1
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
0
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
5
by: Nikola Skoric | last post by:
I have a very simple win32serviceutil script: import win32serviceutil, time win32serviceutil.StartService("burek", "localhost") time.sleep(10) exit() It successfuly imports...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.