How to Control Windows 10 Services From Command Line

Tutorial Dec 5, 2020

Windows services are special programs that run in the background. They don't offer any user interfaces for us to interact with. Windows services can be compared to daemons in Unix Operating Systems. Services can start-up and do what they have to even without having any user signed in. Depending on the service, they may start automatically at boot or start when certain conditions are met.

Windows offer us more than one way to manage services. It can be done though the Windows Task Manager, services.msc and from the command line. If you wish to start, stop and restart services from a GUI, click here. This guide covers the basics of how you can do it though the command line.

Ingredients Required:

  • Command Prompt with admin rights.

Note: To launch a Command Prompt window with admin rights, search for "cmd" in Windows 10 start menu. When you see "Command Prompt" as a result, right-click it and choose "Run as Administrator"

THE COMMANDS

There are two commands at our disposal for controlling services in Windows 10, they are net and sc. Yes, they do differ in what they are capable of doing.

Here are a few things to know about them both;

  • net is older then sc
  • net can only start, stop, pause and continue services
  • sc can create services, delete services, change their configurations, query state, and more
  • sc can be used over the network

GETTING A LIST OF SERVICES

To get a list of all the running services and their information, run the following command;

sc query

To get a list of everything,

sc query state= all

Note: The space after the = sign is deliberate and required.

Like other commands that output data onto the screen, you can redirect it to a .txt file if you want to look through it carefully at a later time.

sc query > running_services.txt

An example of one of the services in the list that the sc query command creates;

SERVICE_NAME: wuauserv
DISPLAY_NAME: Windows Update
        TYPE               : 30  WIN32
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_PRESHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

Note: One major difference to know about sc and net commands is that the SERVICE_NAME is what we will use to control that specific service with sc. While if you are using the net command, you can either use the SERVICE_NAME or the DISPLAY_NAME.

TO STOP A SERVICE

Using sc to stop the "Windows Update" service,

sc stop wuauserv

Using net to stop the "Windows Update" service, with its SERVICE_NAME.

net stop wuauserv

Using net to stop the "Windows Update" service, with its DISPLAY_NAME.

net stop "Windows Update"

TO START A SERVICE

If you know how to stop it, you could easily work out how the start command would look like.

sc start wuauserv
net start wuauserv
net start "Windows Update"

OTHER THINGS

As mentioned above, the net command can only start, stop, pause and continue services. And for most of our common use case scenarios, these actions are enough.

Some of the extra features that sc brings to the table;

To display information about a specific service,

sc query wuauserv

To modify a service entry in the registry and Service Database,

sc config wuauserv

To specifies an action to take upon failure of the service,

sc failure wuauserv

To displays the configuration of a particular service,

sc qc wuauserv

EXTRA NOTE

If you are going to use sc or net in your scripts, an example in .bat files. Do note that the sc command behaves asynchronously while the net command behaves synchronously. Which means, sc won't wait for the service to come to a start or stop like net does. So, depending on the logic of your script and your needs, choose the appropriate one.

Tags

Lime

Simple, like quantum physics.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.