18

Is there any Windows command which will show the status of a single service?

For example, I want to know whether "IIS admin service" is running or not. If it is running the command ouput should be "running".

I tried sc query type= service state= all | find "IIS Admin Service" which displayed the output:

"DISPLAY_NAME: IIS Admin Service"

I also tried net start "IIS Admin Service" | find "Running" which displays:

The requested service has already been started.

More help is available by typing NET HELPMSG 2182.

But it doesn't give me an output such as

"service name" = running / disabled / stopped

Is there a command which has output in this format?

TRiG
  • 1,193
  • 3
  • 14
  • 30
vikas
  • 379
  • 4
  • 6
  • 13

4 Answers4

28

Use the service name and not the display name

sc query iisadmin

jscott
  • 25,114
16

You can use Powershell thus:

Get-Service -name 'IIS Admin Service'

jscott
  • 25,114
vigilem
  • 599
5

This works fine:

sc query "service name" | FIND /C "RUNNING"

%ERRORLEVEL% is either 0 of the service is running, or 1 if it's not. No need for 3rd party tools.

To catch the output of FIND you can use something like this:

sc query "service name" | FIND /C "RUNNING" >NUL && echo Service is running || echo Service is stopped
0

If you're willing to use the excellent Cygwin bash, you can simply write:

sc query "Bonjour Service" |grep -qo RUNNING && echo "Bonjour is ok!" || echo "Apple Bonjour Service not running"

The trick here is to have a proper grep available, so that in this way you can catch the true/false (success) status of command. Here -q is for silent and -o is for just returning the exact match and can probably be omitted. And yes, you need to put your "sc.exe" in your PATH.

not2qubit
  • 282