Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python win32服务自动启动_Python_Windows Services_Pywin32 - Fatal编程技术网

Python win32服务自动启动

Python win32服务自动启动,python,windows-services,pywin32,Python,Windows Services,Pywin32,我正在编写一个python win32服务,下面是我编译服务时的代码片段,它可以工作,但我需要转到services.msc并手动启动它 当我通过以下方式安装服务时,是否有一个选项:myservice.exe安装它将自动启动 下面是我的代码片段: import win32serviceutil import win32service import win32event class SmallestPythonService(win32serviceutil.ServiceFramework):

我正在编写一个python win32服务,下面是我编译服务时的代码片段,它可以工作,但我需要转到services.msc并手动启动它

当我通过以下方式安装服务时,是否有一个选项:myservice.exe安装它将自动启动

下面是我的代码片段:

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)

您可以将
sc.exe
create
命令一起使用

sc create MyPyService binPath= "C:\myservice.exe" DisplayName= "Some Python Service"
更多关于这方面的信息,请访问


win32serviceutil还有一个您可能可以使用的
InstallService()
函数。

我想看看这个。它是一个围绕win32serviceutil的包装,显示了如何自动启动服务。

使用
myservice.exe--startup=auto install
安装服务并将其设置为自动启动。

@Maciejg不适用于我,这里是使用py2exe构建的自动启动服务的解决方案:

myservice.exe -auto -install

Nativ解决方案是最好的解决方案!