The company has a Windows Server 2003, recently did the night maintenance restart plan, the server has two hosting business, the two sets of software has to do boot auto-start, but often the boot does not start or automatic collapse now, to solve this problem has done a batch file to achieve constant monitoring
Implemented using two methods, all bat execution files
1, direct detection once, no operation is started, there is operation to quit! (Here take Baidu Cloud disk to test namely Baidunetdisk.exe)
tasklist/nh|find/i "Baidunetdisk.exe"---------------------------------to run the software process name
If ERRORLEVEL 1 (Start D:\Users\Administrator\AppData\Roaming\baidu\BaiduNetdisk\baidunetdisk.exe) Else (exit)------ ----------------------------------------------------no this process executes the software catalog and executes the file, otherwise exits
2, always on-line monitoring, as long as the process is disconnected or not running will automatically open, using the dead loop to achieve
@echo off
: RESTART
Echo ########################### #时时监控, do not close! #########################
Tasklist/fi "username EQ Administrator" | FIND/C "Baidunetdisk.exe" > Baiduyunpan.txt------Baidunetdisk.exe is the name of the software process to run
set/p num= < baiduyunpan.txt------------------baiduyunpan.txt run output document, multi-process temp.txt full-text name to be modified
del/f Baiduyunpan.txt
Echo%num%
If "%num%" = = "0" start/d "D:\Users\Administrator\AppData\Roaming\baidu\BaiduNetdisk" Baidunetdisk.exe-------------- ------Software Storage Directory + Execute file
Ping-n 10-w 127.0.0.1 >baiduyunpan.txt-----------Here is the use of ping to resolve the stop time
del/f Baiduyunpan.txt
Goto RESTART
2 extension: This execution will display the CMD.EXE window, in order to hide, you can use a simple VB statement to hide the cmd window, you can see in the process of a CMD run process
Step: Write the 2nd. bat file and create a xx.vbs file under the same folder and edit
CreateObject ("Wscript.Shell"). Run "cmd/c Baiduyunpan.bat", 0---------------------full name of the Baiduyunpan.bat file
After completion of the direct execution of Xx.vbs, found no cmd window, in the process will find a more CMD window process
Finish these, then join the regular maintenance, after the server restart, and then run, plus double insurance!
Windows batch processing enables process monitoring to prevent processes from automatically shutting down