As a Windows network, system admin,  we need to check some of the critical services all the time.

Let’s take Active Directory Federation Services as an example, I use a bat script to check and start it

Create a script file called ServiceCheck.bat, and save to c:\scripts:

for /F "tokens=3 delims=: " %%H in ('sc query "adfssrv" ^| findstr " STATE"') do (
if /I "%%H" NEQ "RUNNING" (
REM Put your code you want to execute here
REM For example, the following line
net start "adfssrv"
)
)

Then create a task in Task Scheduler.

The triggers:  I set is Daily, start at 7Am, and Repeat task every 5 minutes. for a duration of 1 day.

Actions: start a program, C:\scripts\ServiceCheck.bat