Windows Service Wrapper:将程序注册为windows系统服务工具

前言

  • wsw 2.3.0

Windows Service Wrapper

WinSW is an executable binary, which can be used to wrap and manage a custom process as a Windows service. Once you download the installation package, you can rename winsw.exe to any name, e.g. myService.exe.

Windows Service Wrapper 可以将 exe应用、Java 的 jar 包等注册为 windows 服务。

项目地址:

  • https://github.com/kohsuke/winsw
  • https://github.com/winsw/winsw

下载 wsw 2.3.0

github上的下载地址:
https://github.com/kohsuke/winsw/releases/tag/winsw-v2.3.0

连不上github可以试试这个下载地址:
http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/2.3.0/

下载WinSW.NET4.exe 和 sample-minimal.xml:
https://github.com/kohsuke/winsw/releases/download/winsw-v2.3.0/WinSW.NET4.exe
https://github.com/kohsuke/winsw/releases/download/winsw-v2.3.0/sample-minimal.xml

配置

以MyApp.exe的配置为例进行说明。
把WinSW.NET4.exe和exe可执行程序在同一个目录下。并将WinSW.NET4.exe更改名称,一般与exe可执行程序名一致。例如,将WinSW.NET4.exe改为MyApp_service.exe。
把sample-minimal.xml改名为MyApp_service.xml。

更改 MyApp_service.xml 配置文件为下面这样:

<configuration>
  
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>MyApp</id>
  <!-- Display name of the service -->
  <name>MyApp</name>
  <!-- Service description -->
  <description>MyAppService (powered by WinSW)</description>
  
  <!-- Path to the executable, which should be started -->
  <executable>D:\MyApp\MyApp.exe</executable>

</configuration>

注册/卸载服务

以管理员身份运行 CMD 命令窗口,输入命令注册为 windows 服务

MyApp_service.exe install		# 注册服务
MyApp_service.exe uninstall		# 卸载服务

启动/停止服务

在 CMD 命令窗口,输入命令启动服务,或我的电脑右键管理,在服务列表中启动服务。

MyApp_service.exe start     # 启动服务
MyApp_service.exe stop     	# 停止服务
MyApp_service.exe restart  	# 重启服务
MyApp_service.exe status   	# 查看服务运行状态

另一组可以启动/停止服务的命令

net start MyApp     # 启动服务
net stop  MyApp     # 停止服务
net stop MyApp && net start MyApp  # 重启服务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值