用py2exe开发windows service

setup.py

from distutils.core import setup
import py2exe
setup(
	service=["RestartHubService"],
	options = { "py2exe": { "includes": "decimal, datetime, email" } }
)

 用上一篇文章中开发的RestartHubService.py作为windows service的主体。

执行python setup.py py2exe,将会build出一个dist目录。把该目录copy到服务器,

执行一下install.bat文件,将安装并启动service

sc stop RestartHubService
sc delete RestartHubService
RestartHubService -install
sc start RestartHubService
sc config RestartHubService start= auto

 

 环境设置:

做windows service的开发,需要设置以下环境:

1. install py2exe
2. install pywin32 http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
3. set python folder to path (!system environment, very important)
move/copy pywintypes26.dll and pythoncom26.dll to c:\Python26\Lib\site-packages\win32, and to c:\Python26
4. install vcredist_x64.exe to support windows service in deploy server

 

你可能感兴趣的:(windows)