@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
Monitoring Windows services to automatically restart services when the service is stopped