一、介绍
如果你想用Python开发Windows程序,并让其开机启动等,就必须写成windows的服务程序Windows Service,用Python来做这个事情必须要借助第三方模块pywin32,自己去下载然后安装(注意下载符合自己OS的版本)。–详见:Python写Windows Service服务程序
二、指令
1.安装服务
python openWebPage.py install
2.让服务自动启动
python openWebPage.py --startup auto install
3.启动服务
python openWebPage.py start
4.重启服务
python openWebPage.py restart
5.停止服务
python openWebPage.py stop
6.删除/卸载服务
python openWebPage.py remove
三、遇到问题
1.服务没有及时响应启动或控制请求
(1)可执行文件的地址为:“C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\win32\PythonService.exe”
(2)执行PythonService.exe,果然,文件无法运行,提示:由于找不到pywintypes27.dll。如果执行成果跳过第3步。
(3)“C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pywin32_system32”打开文件夹;
拷贝“pywintypes39.dll” 和 “pythoncom39.dll” ;
“C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\site-packages\win32”文件夹下粘贴。
(4)核查环境变量
打开系统变量中Path路径,然后加入以下路径:
C:\Users\zhongjianhui\AppData\Local\Programs\Python\Python39\Lib\site-packages\pywin32_system32;
C:\Users\zhongjianhui\AppData\Local\Programs\Python\Python39\Lib\site-packages\win32;
C:\Users\zhongjianhui\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\zhongjianhui\AppData\Local\Programs\Python\Python36\