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

后端 未结 14 1598
天涯浪人
天涯浪人 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:49

    Just to add on to the list if you are using Powershell.

    sc.exe query "ServiceName" | findstr RUNNING
    

    The command below does not work because sc is an alias to Set-Content within Powershell.

    sc query "ServiceName" | findstr RUNNING
    

    find also does not work on Powershell for some reason unknown to me.

    sc.exe query "ServiceName" | find RUNNING
    

提交回复
热议问题