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

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

    I would suggest WMIC Service WHERE "Name = 'SericeName'" GET Started

    or WMIC Service WHERE "Name = 'ServiceName'" GET ProcessId (ProcessId will be zero if service isn't started)

    You can set the error level based on whether the former returns "TRUE" or the latter returns nonzero

提交回复
热议问题