By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

trouble with win32serviceutil

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.