Recently took time to study the Windows and Linux under a service after the automatic restart function, collected some information on the Internet, and tested, here to tidy up. The monitoring of Windows services is described here, and is done by batch processing. This example is an example of monitoring Windows Computer Browser, which is detected every 60 seconds (the interval can be adjusted according to actual needs) and automatically restarted when the discovery service is stopped. The contents of the Autostartservice.bat batch file are as follows
@echo Offrem defines the cycle interval and monitoring services: Set Secs=60set srvname= "Computer Browser" echo.echo ========================= ===============echo = = Query the status of the computer service, ==echo = = %secs% seconds per interval to make a query, &N Bsp ==echo = = If it is found to be stopped, start immediately. ==echo ========================================echo.echo This script monitors the services that are:%srvname%echo. if%srvname%. == . Goto end :chkitset svrst=0for/f "tokens=1* delims="%%a in (' net start ') do if/i "%%a%%b" = =%srvname% Set svrst= 1if%svrst% = = 0 net start%srvname%set svrst=rem The following commands are used for inertia, which may cause the CPU to have a single core full load. Ping-n%secs% 127.0.0.1 > Nulgoto chkit :end Double-click the batch file to run the interface as follows ==================================== ====== Check the status of your computer service, = = 60 seconds per interval, = + nbsp If it is found to be stopped, it is started immediately. ========================================== The service that this script monitors is: "Computer Browser" if computer After the browser is stopped, the batch is detected and restartedThe service, the interface is as follows ========================================== Query the status of computer services, = = & nbsp Query once every 60 seconds, = = Start immediately if it is found to be stopped. ========================================== This script monitoring service is: "Computer Browser" computer Browser The service is starting. Computer Browser Service has started successfully.
Original: http://www.aixchina.net/home/space.php?uid=20260&do=blog&id=38889
[Go] Monitoring Windows services, automatically restart service when service stops