1. 程式人生 > >Windows下通過bat批處理檔案和vbs指令碼實現守護程序

Windows下通過bat批處理檔案和vbs指令碼實現守護程序

set _task=ISMClient.exe
set _svr=C:\ISMClient\ISMClient.exe
set _des=start1.bat
 :checkstart
SET status=1 
(TASKLIST|FIND /I "%_task%"||SET status=0) 2>nul 1>nul
ECHO %status%
IF %status% EQU 1 (goto checkag ) ELSE (goto startsvr)

:startsvr
echo %time% 
echo ********程式開始啟動********
echo 程式重新啟動於 %time% ,請檢查系統日誌 >> restart_service.txt

echo start %_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 ********程式啟動完成********
goto checkstart


:checkag
echo %time% 程式執行正常,10秒後繼續檢查.. 
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs 
cscript //b //nologo %tmp%\delay.vbs 10000 
goto checkstart