@echo offrem 定义循环间隔时间和监测的服务set secs=60set srvname="Apache2.2"echo.echo ========================================echo == 查询计算机服务的状态 ==echo == 每间隔%secs%秒种进行一次查询 ==echo == 如发现其停止 则立即启动 ==echo ========================================echo.if %srvname%. == . goto end :chkitecho.echo %date:~0,10% %time:~0,8%set svrst=0for /F "tokens=1* delims= " %%a in ('net start') do ( if /I "%%a" == %srvname% set svrst=1)if %svrst% == 0 ( echo 服务已宕机,正在为您重新启动服务【%srvname%】 net start %srvname% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs% timeout /t %secs%) else ( echo 服务运行正常【%srvname%】)rem 下面的命令用于延时,否则可能会导致cpu单个核心满载。timeout /t %secs%goto chkit :end