24

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

SC start SERVICE1
SC start SERVICE2

SC stop SERVICE1
SC stop SERVICE2

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

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

1
  • 1
    What windows version?
    – Endoro
    Commented Apr 24, 2013 at 15:22

3 Answers 3

21

Easy, via Powershell:

Get-service SERVICE* | stop-service -force

Get-service SERVICE* | start-service
5
  • 1
    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
    Commented Dec 1, 2016 at 14:23
  • how do i combine these two commands in single go? Commented May 17, 2017 at 15:03
  • @RajaAnbazhagan What do you mean by that? Restarting multiple services? I mean they are already combined here.
    – Wolf
    Commented Feb 26, 2021 at 12:02
  • Nevermind. I was hoping to not use the pipe also this solution was using two commands (one for stop and another for start). I found that the Restart-Service does them both "in single go". Checkout my answer. Commented Feb 28, 2021 at 7:08
  • Not sure if I should start a new topic for that, but how do I filter out the services that are disabled before actually trying to start them superuser.com/q/1742116/1018595 ?
    – Sybuser
    Commented Sep 13, 2022 at 9:20
20

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.

3
  • 1
    The query language is called WQL, BTW. It's a subset of SQL.
    – Bob
    Commented Apr 25, 2013 at 17:58
  • @Bob - Oh. Ya learn something new every day. :>
    – rojo
    Commented Apr 25, 2013 at 17:59
  • 1
    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
    Commented May 20, 2015 at 14:47
2

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*

You must log in to answer this question.

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