Bat 脚本实现监控进程功能

脚本不间断监控notepad.exe,若停止,则自动重启,程序如下:

@echo off
 
set _task = notepad.exe
set _svr  = c:\windows\notepad.exe
set _des  = start.bat
 
:checkService
for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
    if %%n==%_task% (goto checkMessage) else goto restartService
)
  
:restartService
echo %time% 
echo ********程序开始启动********
echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.txt
echo start %_svr% > %_des%
echo exit >> %_des%
start %_des%
REM set /p=.<nul 不换行在屏幕输出....
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 .
del %_des% /Q
echo ********程序启动完成********
goto checkService
 
 
:checkMessage
echo %time% 程序运行正常,5秒后继续检查.. 
ping localhost -n 5 
goto checkService
posted @ 2019-06-26 17:09  店小六  阅读(1615)  评论(1编辑  收藏  举报