我正在编写一个 python win32 服务,下面是我编译服务时的代码片段,但我需要转到 services.msc 并手动启动它。
当我通过以下方式安装服务时是否有一个选项:myservice.exe install it will starts automatically?
下面是我的代码片段:
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
安装服务并将其设置为自动启动。
关于Python win32 服务自动启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4538848/