PS: WinSW is a software that can register any application as a service

1. Download WinSW

  • Winsw: github.com/winsw/winsw…

Winsw-x64.exe

2. Rename the file

Rename winsw-x64.exe to winsw.exe,

3. Add configuration file winsw.xml

Note: you must change exe and XML files to the same name

<service>
	<! -- Service ID. It should be unique in the entire Windows system -->
	<id>demo</id>
	<! -- Service name -->
	<name>demo</name>
	<! -- Service Description -->
	<description>This service runs the Demo service</description>
	<! -- The path to the executable that should be launched, the Java environment must be installed -->
	<executable>java</executable>
	<! -- Execute parameter -->
	<arguments>-jar demo.jar</arguments>
	<! -- Boot up -->
	<startmode>Automatic</startmode>
	<! -- Log directory -->
	<logpath>logs\service</logpath>
	<! -- Log Configuration -->
	<logmode>none</logmode>
</service>
Copy the code

4. Installation services

[win+R] Open, enter CMD to go to winsw.exe directory

Winsw.exe install winsw.exe installCopy the code

5. Check whether the service is installed

【win+R】 Open and type services.msc

Common commands

Exe uninstall # Start service. Winsw. exe start # Stop service. Winsw. exe stop # Restart service Winsw. exe statusCopy the code

A common command batch file is included

  1. Installation services
  2. Unloading service
  3. Start the service
  4. Stop the service
  5. Restart the service
  6. State of the service
@echo off CHCP 65001 > Nul rem winsw.exe name, pay attention to change !!!! Set name=winsw.exe REM project name Set Project =JAR Package Register WIN system application service REM title [%project%], time :%DATE% %time% REM menu option :again echo -------------------------------------------------------------- echo %project% echo -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- echo 1, installation services. Echo 2, unloading service. Echo 3, start the service. Echo 4, stop the service. The echo 5, restart services. 6, echo state services. Echo -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the set/p num = please input selection and press enter:  if "%num%"=="1" goto install if "%num%"=="2" goto uninstall if "%num%"=="3" goto start if "%num%"=="4" goto stop if "%num%"=="5" goto restart if "%num%"=="6" goto status Echo The batch processing automatically exits. Exit :install cls. \%name% install echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = pause goto again: uninstall the CLS Uninstall echo. \ % name % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = pause Goto again: start CLS. \ % name % start echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo ==================================== pause goto again :restart cls .\%name% restart echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = pause goto again: stop CLS Stop echo. \ % name % = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = pause goto Again: the status of CLS. \ % name % status echo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = echo completes the echo ==================================== pause goto againCopy the code