How do I determine the status of a specific service?
I'd like to run a command that will give me the status of a specific windows service. Using sc query, I was able to get this information, see below.
C:\Windows\System32>sc query "IBM Cognos"
SERVICE_NAME: IBM Cognos
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_C开发者_开发百科ODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
The only bit of information that I really need to access is the "STATE". Can I filter the output so I am only seeing the STATE or "1 STOPPED"? I was hoping I could do something like:
sc query[STATE] "IBM Cognos"
My ultimate goal is to run a .bat file that will output the status of a service to a file. I can then read that file from another program and use that value to determine whether I should display a green icon indicating "started" or a red icon indicating "stopped" to the user in the UI.
Thanks in advance for your help,
Jeff
How about:
sc query "IBM Cognos" | find "STATE"
Should return something like:
STATE : 1 STOPPED
精彩评论