下载winsw(Windows Service Wrapper)是一个开源项目,它可以让我们快速把一个可执行的程序注册为Windows的系统服务。
下载页面如下: (下载地址)
需要下载可执行程序(WinSW.NET4.exe)以及配置文件(sample-minimal.xml)。
-
可执行程序有WinSW.NET2.exe以及WinSW.NET4.exe,根据当前系统的.NET版本进行选择。如果是Win10建议使用WinSW.NET4.exe。
-
配置文件有sample-minimal.xml以及sample-allOptions.xml, sample-allOptions.xml包括所有配置项,sample-minimal.xml为可使用的最小配置,使用这个即可满足条件。
sample-minimal.xml内容如下:
配置myapp MyApp Service (powered by WinSW) This service is a service cratead from a minimal configuration %BASE%myExecutable.exe
以安装X:Test.exe为例,将WinSW.NE4.EXE和sample-minimal.xml放在文件夹(X:winsw)内,将其分别重命名为Test.exe和Test.xml(必须同名,否则会失败),将Test.xml修改为:
安装100001 Test Service of Test X:Test.exe
以管理员权限运行cmd,进入目录X:winsw,运行命令 Test.exe install即可完成安装。
其他常用命令如下:
- Test.exe uninstall
- Test.exe start
- Test.exe restart
- Test.exe stop
如果需要设置多个程序,需要设置多个配置文件,winsw不支持一个配置文件设置多个程序。
参考用winsw让任何Windows程序都能运行为服务
windows中使用winsw进行服务管理开启启动服务



