@echo off
set _task=nodepad++.exe
set _svr=%cd%\%_task%
set _des=start.bat
:checkstart
for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
if %%n==%_task% (goto checkag) else goto startsvr
)
:startsvr
echo %time%
echo ********Program Start********
echo Program Start time at %time% ,Please check the log >> restart_service.log
echo %_svr% > %_des%
echo exit >> %_des%
start %_des%
set/p=.<nul
for /L %%i in (1 1 10) do set /p a=.<nul&ping.exe /n 2 127.0.0.1>nul
echo .
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
cscript //b //nologo %tmp%\delay.vbs 10000
del %_des% /Q
echo ********Program Startup Completion********
goto checkstart
:checkag
echo %time% The program runs normally and continues to check after 10 seconds...
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
cscript //b //nologo %tmp%\delay.vbs 10000
goto checkstart
如果不想显示守护进程页面可使用 vb 隐藏,将上面的守护代码保存为 watchdog.bat。
set ws=WScript.CreateObject("WScript.Shell")
ws.Run "watchdog.bat",0
把上面的代码保存为watchdog.vbs。守护进程需要从任务管理器中进行关闭。
网友评论