How to test whether a service is running from the command line

后端 未结 14 1660
天涯浪人
天涯浪人 2020-12-12 18:59

I would like to be able to query whether or not a service is running from a windows batch file. I know I can use:

sc query \"ServiceName\"

14条回答
  •  失恋的感觉
    2020-12-12 19:39

    Use Cygwin Bash with:

    sc query "SomeService" |grep -qo RUNNING && echo "SomeService is running." || echo "SomeService is not running!"
    

    (Make sure you have sc.exe in your PATH.)

提交回复
热议问题