trouble with win32serviceutil

E

Erik Myllymaki

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)
 
E

Erik Myllymaki

Erik said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top