Python win32 服务自动启动

标签 python windows-services pywin32

我正在编写一个 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/

相关文章:

python - 是否可以在 python 中获取事件窗口的当前插入点(文本光标/插入符)?

python - 尝试后如何正确等待检查 Excel 实例是否已关闭?

python - 我的 pyuic 转换后的文件无法打开

python - Pandas str.split (' ' ) 返回 NaN

python - 递归函数调用

memory - JBoss作为Windows服务。在哪里可以设置JAVA_OPTS?

c# - 处理 Windows 服务停止/暂停请求期间的延迟

c# - SEH异常 (0x80004005) : External component has thrown an exception

python - 使用 python 读取 csv 文件让我到达最后一行

python - 有没有使用 pywin32 createprocessasuser 并获取输出的好例子?