@echo off
REM defines the cycle interval time and monitoring services:
Set secs=60
Set Srvname= "ServerName"
Echo.
Echo ========================================
echo = Query the status of the computer service, = =
echo = = One query per interval of%secs% seconds, = =
echo = starts immediately if it is found to be stopped. ==
Echo ========================================
Echo.
Echo This script monitors the service as:%srvname%
Echo.
If%srvname%. == . Goto END
: Chkit
Set svrst=0
for/f "Tokens=1* delims="%%a in (' net start ') do if/i "%%a%%b" = =%srvname% Set svrst=1
If%svrst% = = 0 net start%srvname%
Set svrst=
REM The following commands are used for inertia, which may cause the CPU to have a single core full load.
Ping-n%secs% 127.0.0.1 > nul
Goto Chkit
: End
Double-click the batch file to run the following interface
========================================
= = Query the status of the computer service, = =
= = One query per interval of%secs% seconds, = =
= = starts immediately if it is found to be stopped. ==
========================================
The services that this script monitors are:%srvname%
If%srvname% is stopped, the batch will restart the service after it is detected and the interface is as follows
========================================
= = Query the status of the computer service, = =
= = One query per interval of%secs% seconds, = =
= = starts immediately if it is found to be stopped. ==
========================================
The services that this script monitors are:%srvname%
%srvname% Service is starting
The%srvname% service has started successfully.
Create a new Autostartservice.bat, paste the above text, "ServerName" into the service that needs to be monitored
Monitoring Windows services to automatically restart services when the service is stopped