在机器启动时运行Windows服务

时间:2011-11-05 13:19:40

标签: python windows windows-services

我有一个用Python编写的Windows服务。我想在机器启动时自动启动它。

我该怎么做?

class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "Service"
_svc_display_name_ = "Myservice"

def __init__(self,args):
    win32serviceutil.ServiceFramework.__init__(self,args)
    self.hWaitStop = win32event.CreateEvent(None,0,0,None)
    #socket.setdefaulttimeout(60)

def SvcStop(self):
    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
    win32event.SetEvent(self.hWaitStop) 

def SvcDoRun(self):
    servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_,''))
    self.timeout = 120000
    self.main()              #//thread.start_new_thread(main)

def main(self):
        pass

def ctrlHandler(ctrlType):
    return True         

if __name__ == '__main__':
    win32api.SetConsoleCtrlHandler(ctrlHandler, True)
    win32serviceutil.HandleCommandLine(AppServerSvc)

1 个答案:

答案 0 :(得分:0)

尝试任务计划程序:

http://support.microsoft.com/kb/308569