Windows Service Wrapper 一个将可执行文件封装为windows服务的利器

Windows Service Wrapper 一个将可执行文件封装为windows服务的利器

License

WinSW是一个可执行二进制文件,可用于包装和管理作为Windows服务的自定义进程。下载安装包后,您可以将 WinSW.exe 重命名为任何名称,例如 MyService.exe 。

支持的平台

WinSW提供了.NET Framework 2.0、4.0和4.6.1的可执行文件。它可以在安装了这些版本的.NET Framework的Windows平台上运行。对于没有.NET Framework的系统,该项目提供了基于.NET Core 3.1的本机64位和32位可执行文件。

下载

WinSW 可在 GitHub ReleasesNuGet上进行下载.

用法

WinSW通过配置文件(提供xml和yaml两种格式)的方式进行管理: Main XML configuration file 和 Main YAML configuration file .

配置完成后,可配合以下命令进行windows服务的安装、启动、停止等操作:

  • install 将服务安装到Windows Service Controller.
  • uninstall 卸载服务和上面相反的操作。
  • start 启动服务,该服务必须已经安装。
  • stop 停止服务。
  • stopwait 停止服务并等待,直到它实际上停止为止。
  • restart 重新启动服务。如果该服务当前未运行,则此命令的作用类似于start
  • status 检查服务的当前状态。

大多数命令都需要管理员权限才能执行。

执行格式: MyService.exe install

XML配置格式

<service>
  
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>gocron</id>
  <!-- Display name of the service -->
  <name>gocron Service (powered by WinSW)</name>
  <!-- Service description -->
  <description>This service is a crontab</description>
  
  <!-- Path to the executable, which should be started -->
  <executable>F:\gocron\gocron-windows-amd64\gocron.exe</executable>
  <startarguments> web </startarguments>
  <log mode="roll"></log>
</service>

备注: WinSW.exe 和对应的xml配置文件进行重命名时采用相同的文件名。如: myserver.exe myserver.xml

posted @ 2020-08-21 11:14  开怀的猫  阅读(1753)  评论(0编辑  收藏  举报