How do you check if a service is running using batch file?

How do you check if a service is running using batch file?
Answer
Explanation
  1. @ECHO OFF ==> To hide the text.
  2. 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. …
  3. if /I “%%H” NEQ “RUNNING” ( ==> condition where the service is running.
  4. exit ==> exit from batch file.
20 окт. 2018 г.
 

Tìm kiếm

Back
Top