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) -- http://mail.python.org/mailman/listinfo/python-list