windows service restart script

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_42227818/article/details/100574521

OFF @echo
REM cycle defined time interval and monitoring services:
SET. 5 secs =
SET srvname = "Tomcat7"

echo.
echo ========================================
echo == queries computer services state, ==
echo == intervals% secs% seconds a query, ==
echo == found it to stop, then start immediately. ==
echo ========================================
echo.
Echo This script monitoring service is:%% srvname
echo.

if %srvname%. == . goto end

: chkit
SET svrst = 0
for / F. "tokens. 1 * = delims =" %% A in ( 'NET Start') do IF / the I "%% A %% B" ==% srvname% SET = svrst. 1
IF% % == 0 NET Start svrst%% srvname
the SET svrst =
REM the following command is used to delay, otherwise it could lead to a single core cpu full.
-n% secs% 127.0.0.1 the ping> NUL
GOTO chkit

:end

Double-click the batch file, run the following interface

========================================
== status inquiry computer services, ==
== interval of 60 seconds once for each query ==
== found it to stop, then start immediately. ==

This script monitoring service is: "Computer Browser"

If the Computer Browser stop, after detecting the batch will restart the service, the interface is as follows

== query the status of computer services, ==
== interval of 60 seconds once for each query ==
== found it to stop, then start immediately. ==

This script monitoring service is: "Computer Browser"

Computer Browser service is starting.
Computer Browser service has started successfully.

:RESTART

tasklist /FI "username eq luoca" | find /C "QQ.exe" > temp.txt
set /p num= < temp.txt
del /F temp.txt
echo %num%
if "%num%" == "0" start /D "D:\QQ\Bin\" QQ.exe
ping -w 200000 0.0.0.1 > temp.txt
del /F temp.txt
goto RESTART

Guess you like

Origin blog.csdn.net/qq_42227818/article/details/100574521