This article is transferred from the network, because cannot find the original author, therefore cannot know the source. If you are lucky enough to have the original author see, please contact me plus. First reproduced here.
In recent days, overtime and crazy lost, every night can not sleep. 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 offSet_task=notepad.EXESet_svr=c:\windows\notepad.EXESet_des=Start.Bat: Checkstart for/F "tokens=5"%%n in (' Qprocess.exe ^|Find"%_task%") Do(if%%n==%_task% (GotoCHECKAG)Else GotoStartsvr): StartsvrEcho% Time% Echo******** program starts to start ********EchoProgram restarts at% Time%, please check system log >> Restart_service.txtEcho 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>nulEcho.EchoWscript.Sleep wscript.arguments (0) >%tmp%\delay.VBS cscriptb//nologo%tmp%\delay.vbs 10000del%_des%/QEcho******** program start complete ********GotoCheckstart: CheckagEcho% Time% Program is running normally, check again after 10 seconds.EchoWscript.Sleep wscript.arguments (0) >%tmp%\delay.VBS cscriptb//nologo%tmp%\delay.vbs 10000GotoCheckstart
Windows under Bat Batch implementation daemon