服务封装软件 winsw

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.xmlsample-allOptions.xml包括所有配置项,sample-minimal.xml为可使用的最小配置,使用这个即可满足条件。

sample-minimal.xml内容如下:

<configuration>

  <!-- ID of the service. It should be unique accross the Windows system-->
  <id>myapp</id>
  
  <!-- Display name of the service -->
  <name>MyApp Service (powered by WinSW)</name>
  
  <!-- Service description -->
  <description>This service is a service cratead from a minimal configuration</description>
  
  <!-- Path to the executable, which should be started -->
  <executable>%BASE%\myExecutable.exe</executable>
  
</configuration>

配置

以安装X:\Test.exe为例,将WinSW.NE4.EXEsample-minimal.xml放在文件夹(X:\winsw\)内,将其分别重命名为Test.exeTest.xml(必须同名,否则会失败),将Test.xml修改为:

<configuration>

  <!-- ID of the service. It should be unique accross the Windows system-->
  <id>100001</id>
  
  <!-- Display name of the service -->
  <name>Test</name>
  
  <!-- Service description -->
  <description>Service of Test</description>
  
  <!-- Path to the executable, which should be started -->
  <executable>X:\Test.exe</executable>
  
</configuration>

安装

以管理员权限运行cmd,进入目录X:\winsw\,运行命令 Test.exe install即可完成安装。

其他常用命令如下:

  • Test.exe uninstall
  • Test.exe start
  • Test.exe restart
  • Test.exe stop

其他

如果需要设置多个程序,需要设置多个配置文件,winsw不支持一个配置文件设置多个程序。

参考

用winsw让任何Windows程序都能运行为服务
windows中使用winsw进行服务管理开启启动服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值