15

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,181
  • 3
  • 13
  • 30
vikas
  • 349
  • 3
  • 6
  • 13

4 Answers4

25

Use the service name and not the display name

sc query iisadmin

jscott
  • 24,484
  • 8
  • 79
  • 100
jonathan warren
  • 351
  • 2
  • 4
  • This is the way I do it. You may need to look at the Properties for the Service in the Services console (Or just do sc query to get the list of them all and find the one you want) – Taegost Feb 08 '16 at 17:42
  • The command which you gave worked for me thanks a lot – vikas Feb 09 '16 at 12:34
15

You can use Powershell thus:

Get-Service -name 'IIS Admin Service'

jscott
  • 24,484
  • 8
  • 79
  • 100
vigilem
  • 579
  • 2
  • 7
3

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
  • 281
  • 1
  • 3
  • 10