使用 WinSW 把可执行文件安装为服务
本文最后更新于 2024年10月13日 晚上
参数列表
| Command | Description |
|---|---|
| install | Installs the service. |
| uninstall | Uninstalls the service. |
| start | Starts the service. |
| stop | Stops the service. |
| restart | Stops and then starts the service. |
| status | Checks the status of the service. |
| refresh | Refreshes the service properties without reinstallation. |
| customize | Customizes the wrapper executable. |
| dev ps | Draws the process tree associated with the service. |
| dev kill | Terminates the service if it has stopped responding. |
| dev list | Lists services managed by the current executable. |
使用方式
先说结论
若
WinSW.exe和myapp.xml不在同一目录- 使用
WinSW.exe install .\myapp.xml操作服务
- 使用
若
WinSW.exe和myapp.xml在同一目录- 可以使用
WinSW.exe install .\myapp.xml操作服务 - 也可以把
WinSW.exe重命名为myapp.exe,然后使用myapp install操作服务
- 可以使用
服务示例:
chfs-service.xml:
1 | |
全局方式
- 从 发布页面
下载
WinSW.exe - 创建一个专门用来放 xml 文件的目录,把
WinSW.exe放入其中,创建myapp1.xml、myapp2.xml… - 然后可以使用形似下面的命令操作每个服务
1 | |
也可以随便找个其他地方,把
WinSW.exe放入其中,并加入PATH,总之能访问到 WinSW.exe 就行
捆绑方式
- 下载
WinSW.exe - 创建一个文件夹,把
WinSW.exe放入其中并重命名为myapp.exe - 在相同文件夹内创建
myapp.xml - 然后可以使用形似下面的命令操作服务
1 | |
目录结构:
1 | |
使用 WinSW 把可执行文件安装为服务
https://blog.oopsky.top/post/376ebc48/