470,834 Members | 1,714 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 5319
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by max | last post: by
1 post views Thread by Jim Bancroft | last post: by
6 posts views Thread by Daniel Walzenbach | last post: by
5 posts views Thread by Nikola Skoric | last post: by
reply views Thread by mrchatgroup | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.