Windows 10 – Check for service status and restart if not running

from: https://stackoverflow.com/questions/3325081/how-to-check-if-a-service-is-running-via-batch-file-and-start-it-if-it-is-not-r

for /F “tokens=3 delims=: ” %%H in (‘sc query “MyServiceName” ^| 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 “MyServiceName”
)

)

This entry was posted in Labs and tagged . Bookmark the permalink.

Comments are closed.