目录
    
    
    
    前言
   
- 
     查看电脑 net framework 版本
在命令行工具中运行:
dir /b %windir%\Microsoft.NET\Framework\v*
可查看列表,最新的即为你电脑安装的版本。
示例:

可见我的是 4.0。
如果想要查看更细节的版本,操作过程如下:
     - 
     电脑联网并能够无障碍访问
GitHub
并下载相关文件。 
    
    
    下载
    
     winsw
    
   
winsw
    WinSW下载地址:https://github.com/winsw/winsw/releases
    
    根据我电脑
    
     .NET
    
    版本下载相关文件:
   
- 
     
WinSW.NET4.exe
 - 
     
sample-allOptions.xml
(或者 sample-minimal.xml) 
    
    
    编写配置文件
   
    我们需要编写一个和程序(WinSW.NET4.exe)同名的XML文件(WinSW.NET4.xml)作为winsw的配置文件。
    
    下面简要的设置一个可以满足日常需求的带配置文件的程序的配置。
    
    如:
   
- 
     程序位于:
D:\program\my.exe
 - 
     可执行程序对应的配置文件为:
D:\program\my.conf
原始方法我在命令行工具中执行程序的方法为:D:\program\my.exe -c D:\program\my.conf
接下来就是程序示例: 
<service>
  
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>myServiceId</id>
  <!-- Display name of the service -->
  <name>My Service (powered by WinSW)</name>
  <!-- Service description -->
  <description>This service is a service created from a minimal configuration, for  remote control. </description>
  
  <!-- Path to the executable, which should be started -->
  <executable>D:\program\my.exe</executable>
  <arguments>-c D:\program\my.conf</arguments>
  <!--
    OPTION: onfailure
    Defines a sequence of actions, which should be performed if the managed executable fails.
    Supported actions: restart, reboot, none
  -->  
  <onfailure action="restart" delay="60 sec"/>
  <onfailure action="restart" delay="120 sec"/>
  <!--
    OPTION: log
    Defines logging mode for logs produced by the executable.
    Supported modes:
      * append - Rust update the existing log
      * none - Do not save executable logs to the disk
      * reset - Wipe the log files on startup
      * roll - Rotate logs based on size
      * roll-by-time - Rotate logs based on time
      * rotate - Rotate logs based on size, (8 logs, 10MB each). This mode is deprecated, use "roll"
    Default mode: append
    
    Each mode has different settings. 
    See https://github.com/kohsuke/winsw/blob/master/doc/loggingAndErrorReporting.md for more details
  -->
  <log mode="reset">
    <!--
    <setting1/>
    <setting2/>
    -->
  </log>
    <!--
      OPTION: startmode
      Defines start mode of the service.
      Supported modes: Automatic, Manual, Boot, System (latter ones are supported for driver services only)
      Default mode: Automatic
    -->
    <startmode>Automatic</startmode>
</service>
    
    
    注册服务
   
    编写好配置文件之后,记得把配置文件和可执行文件放在一起,这样winsw才能正确识别配置文件。然后我们打开一个
    
     管理员权限
    
    的命令提示符或Powershell窗口,然后输入
    
     WinSW.NET4.exe install
    
    。
    
    
    
    对应的服务为:
    
    
   
    
    
    卸载服务
   
    同理,
    
     WinSW.NET4.exe uninstall
    
    
    
   
 
版权声明:本文为orDream原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。