winsw (Windows Service Wrapper) is an open source project that allows us to quickly register an executable program as a Windows system service.
download
The download page is as follows: ( download link )
Need to download executable program ( WinSW.NET4.exe
) and configuration file ( sample-minimal.xml
).
-
The executable programs are
WinSW.NET2.exe
as well as thoseWinSW.NET4.exe
that can be selected according to the .NET version of the current system. If it is Win10, it is recommendedWinSW.NET4.exe
. -
The configuration file has
sample-minimal.xml
andsample-allOptions.xml
,sample-allOptions.xml
including all configuration items,sample-minimal.xml
is the smallest configuration that can be used, and the conditions can be met by using this.
sample-minimal.xml
The content is as follows:
<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>
Configuration
Take installation X:\Test.exe
as an example, put WinSW.NE4.EXE
and sample-minimal.xml
in the folder ( X:\winsw\
), rename them to Test.exe
and respectively Test.xml
( must have the same name, otherwise it will fail ), and Test.xml
modify it to:
<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>
installation
With administrator privileges to run cmd , enter the directory X:\winsw\
, run the command Test.exe install
to complete the installation.
Other commonly used commands are as follows:
- Test.exe uninstall
- Test.exe start
- Test.exe restart
- Test.exe stop
other
If you need to set multiple programs, you need to set multiple configuration files. Winsw does not support one configuration file to set multiple programs.
reference
Use winsw to make any Windows program run as a service
. Use winsw for service management in windows. Turn on and start the service.