- 帖子
- 9
- 积分
- 109
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2009-4-15
|
Bat脚本实现监控进程功能
脚本不间断监控notepad.exe进程是否执行,若停止,则自动重启该进程,程序如下:
1 @echo off
2
3 set _task = notepad.exe
4 set _svr = c:\windows\notepad.exe
5 set _des = start.bat
6
7 :checkService
8 for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
9 if %%n==%_task% (goto checkMessage) else goto restartService
10 )
11
12 :restartService
13 echo %time%
14 echo ********程序开始启动********
15 echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.txt
16 echo start %_svr% > %_des%
17 echo exit >> %_des%
18 start %_des%
19 REM set /p=.<nul 不换行在屏幕输出....
20 set /p=.<nul
21 for /L %%i in (1 1 10) do set /p a=.<nul & ping.exe /n 2 127.0.0.1>nul
22 echo .
23 del %_des% /Q
24 echo ********程序启动完成********
25 goto checkService
26
27
28 :checkMessage
29 echo %time% 程序运行正常,5秒后继续检查..
30 ping localhost -n 5
31 goto checkService
以上脚本是引用的。供参考 |
|