Python win32服务自动启动

我正在编写一个python win32服务下面是我的代码片段,当我编译它的工作,但我需要去services.msc并手动启动它。 当我安装serivce时有没有选项:myservice.exe install它会自动启动吗? 下面是我的代码片段:
import win32serviceutil
import win32service
import win32event

class SmallestPythonService(win32serviceutil.ServiceFramework):
   _svc_name_ = "ser_name"
   _svc_display_name_ = "ser_descryption"
   #_svc_description_='ddd'
   def __init__(self, args):

      win32serviceutil.ServiceFramework.__init__(self, args)
                    self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):

       self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
       win32event.SetEvent(self.hWaitStop)

   def SvcDoRun(self):

       win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)

if __name__=='__main__':

    win32serviceutil.HandleCommandLine(SmallestPythonService)
    
已邀请:
使用
myservice.exe --startup=auto install
安装服务并将其设置为自动启动。     
我会看看这个ActiveState配方。它是win32serviceutil的包装器,展示了如何自动启动服务。     
您可以使用
create
create
命令。
sc create MyPyService binPath= "C:myservice.exe" DisplayName= "Some Python Service"
有关此内容的更多信息,请访问Microsoft KB251192。 win32serviceutil也有一个你可以使用的
InstallService()
功能。     
@Maciejg对我不起作用,这里的解决方案是使用py2exe自动启动我的服务:
myservice.exe -auto -install
    

要回复问题请先登录注册