1.环境设置
python要开发windows程序,首先必须先安装好pywin32,还要安装pyinstaller
pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
2.编写代码,以下是通用的python编译成windows服务程序的模板,不要问我为什么,我也是网上找的,可在SvcDoRun编写自己的业务代码
#encoding=utf-8
import win32serviceutil
import win32service
import win32event
import os
import logging
import inspect
class PySerTest(win32serviceutil.ServiceFramework):
_svc_name_ = "PySerTest"
_svc_display_name_ = "Py Service Test"#服务显示的名称,可以自己修改
_svc_description_ = "This is a python service test code "//服务显示的描述
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0