Trần Yến Nhi
Member
How do you check if a service is running using batch file?
Answer
Explanation
Answer
Explanation
- @ECHO OFF ==> To hide the text.
- for /F “tokens=3 delims=: ” %%H in (‘sc query “MyServiceName” ^| findstr ” STATE”’) do ( ==> this line will query the service and find string “STATE” on the result. …
- if /I “%%H” NEQ “RUNNING” ( ==> condition where the service is running.
- exit ==> exit from batch file.