17

Currently, we have setup a .BAT file which lists all services to start / stop them eg.

SC start SERVICE
SC start SERVICE

SC stop SERVICE
SC stop SERVICE

We add new services all the time and the list grows and is difficult to maintain the batch file.

Is it possible to use a WILDCARD like 'SC start SERVICE*' or something?

  • What windows version? – Endoro Apr 24 '13 at 15:22
16

You can use wmic and SQL-ish wildcard syntax.

From a cmd console:

wmic service where "name like 'SERVICE%'" call startservice

From a .bat script:

wmic service where "name like 'SERVICE%%'" call startservice

Available verbs include startservice, stopservice, pauseservice, resumeservice, and others. Do wmic service call /? for more info.

  • 1
    The query language is called WQL, BTW. It's a subset of SQL. – Bob Apr 25 '13 at 17:58
  • @Bob - Oh. Ya learn something new every day. :> – rojo Apr 25 '13 at 17:59
  • Just wanted to add one more thing. I ran into an error where the service name was not recognized. Turns out a service has a Service Name and a Display Name. The Service Name should be used, not the Display Name. You can find the Service Name with sc query – jdramer May 20 '15 at 14:47
11

Easy, via Powershell:

Get-service SERVICE* | stop-service -force

Get-service SERVICE* | start-service
  • I upvoted this one because it runs WAY faster than wmic. On my machine it takes about 2 milliseconds to get a list of services this way. It takes about 13000 milliseconds using wmic. – arjabbar Dec 1 '16 at 14:23
  • how do i combine these two commands in single go? – Raja Anbazhagan May 17 '17 at 15:03
0

if you want a One Line command,

You can use Restart-Service Cmdlet which is pre built in powershell.

To use Restart-Service simply call the cmdlet followed by the service name:

Restart-Service mysql57

To restart multiple services just specify the name of each service, separated by commas:

Restart-Service mysql57,apache

If you prefer, add the -displayname parameter and specify the service display name (the name shown in the Services snap-in) instead:

Restart-Service -displayname "Mysql 5.7 server"

This Cmdlet accepts wildcard matching as well. To restart all services starting with "mysql":

Restart-Service mysql*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.