16

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?

4 Answers 4

26

Use the service name and not the display name

sc query iisadmin

2
  • 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 8, 2016 at 17:42
  • The command which you gave worked for me thanks a lot
    – vikas
    Feb 9, 2016 at 12:34
15

You can use Powershell thus:

Get-Service -name 'IIS Admin Service'

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .