Wednesday, May 30, 2018

Check Windows service and start if down

@ECHO OFF
SET SName=%~1
 
SC QUERYEX "%SName%" | FIND "STATE" | FIND /v "RUNNING" > NUL && (
    ECHO %SName% is not running
    ECHO START %SvcName%
 
    NET START "%SName%" > NUL || (
        ECHO "%SName%" wont start
        EXIT /B 1
    )
    ECHO "%SName%" is started
    EXIT /B 0
) || (
    ECHO "%SName%" is running
    EXIT /B 0
)