0

I use sc.exe to stop/start services on a remote \server in a pre/post build batch. Unfortunately sc does not seem to deliver any information about the service being deactivated or not which leads to an accumulating timeout when using the sc start command on deactivated services. Does anyone know an alternative to check the deactivated state on a remote service in the command line?

needfulthing
  • 1,056
  • 11
  • 21

1 Answers1

1

This is what you are looking for..

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

look down for the WMI/WMIC options. You will need to modify the command line slightly to attach to a remote machine.

If you need to know the start mode property, add it to the command line like this:

wmic /locale:ms_409 service where (name="RemoteRegistry") get state, StartMode /Value

This produces:

StartMode=Disabled
State=Stopped

I am not marking as duplicate because your wording and needs are a little bit different.

Señor CMasMas
  • 4,290
  • 2
  • 14
  • 21
  • Hi thanks for the answer. The featured wmic command does not separate between stopped and disabled services. It just reports "stopped" for both. I think the problem is that "disabled" is not a service state in the sense of the commands or Windows in common. – needfulthing Jun 17 '19 at 16:44
  • Yes, @needfulthing.. it will do the trick for you. You need to query for other properties. Please see my amended answer. Good luck! – Señor CMasMas Jun 17 '19 at 19:03
  • Ah, I didn't recognize the "startmode" option. That works! – needfulthing Jun 19 '19 at 15:45