2020/11/11

用批处理自动重启被停止的Windows服务

Windows Server上某个服务无故被停止,在尚未找出原因前,先写个bat批处理脚本,让它定期检查服务是否停止了,若是,就启动它。

直接上源代码:

@echo off

sc query LeadService | find "STATE" | find "RUNNING"

if %errorlevel% == 1 (

  echo The service is stopped.

  net start LeadService

  echo %date% %time% Restart >> c:\LeadService.log

) else (

  echo The service is running.

  echo %date% %time% Do Nothing >> c:\LeaderService.log

)

没有评论: