Development Department of a core program will always be down, and then need to go manually, and the security level of this service is very high, only I can operate, make my night old can't sleep, last night really can't stand, think of the shell daemon process previously written under HP-UX, This back to a Windows bat version of the daemon, then the evening thought is very slow, called a brother let him write, go up after the effect is good, at least last night I sleep 7 hours. Early to change the program to improve a number of functions, such as recording. Realize:
Check if there is a notepad, if you want to use it as your own process name, if the process is down, it will automatically restart (will generate a start.bat in the current directory)
@echo off
Set _task=notepad.exe
Set _svr=c:/windows/notepad.exe
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 starts to start ********
Echo Program restarts on%time%, please check system log >> Restart_service.txt
echo Start%_svr% >%_des%
Echo Exit >>%_des%
Start%_des%
Set/p=.<nul
FOR/L%%i in (1 1) 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 start complete ********
Goto Checkstart
: Checkag
Echo%time% program is running normally, check again after 10 seconds.
echo Wscript.Sleep wscript.arguments (0) >%tmp%/delay.vbs
cscript//b//nologo%tmp%/delay.vbs 10000
Goto Checkstart
http://blog.csdn.net/jiangxinyu/article/details/5217342
Windows under Bat Batch implementation daemon (with log)