Config Server Firewall

SC Command – Manage Services in Windows

You can use the sc (service controller) command to manage Windows services from the command line.

SC Command - Manage Services in Windows

In this tutorial, we will learn how to start, stop, and view Windows services using the sc command.

Check Service Status

The sc query command list all running services on a Windows computer:

sc query

To list all services, including services running, stopped, or paused, run the sc command as follows:

sc query state=all

The following command list inactive services:

sc query state=inactive

In the following example, we save the output of the sc query command to a file called services.txt:

sc query > services.txt

To get information about a specific service, run the sc query command followed by the name of the service:

sc query service-name

The service-name should be the SERVICE_NAME output from the sc query command. We are using the Spooler (Print Spooler) service for the following example:

sc query Spooler

Here is the output of this command:

windows spooler service

The queryex option display more information, including the PID of a running service:

sc queryex Spooler

To see the configuration of a particular service, you can use the sc qc command:

sc qc Spooler

Here is the output that includes startup type, dependencies, and the full path of the executable that runs the service.

the sc qc command shows configuration of a particular service

To see the description for a service, use the qdescription option:

sc qdescription Spooler

Start, Pause, Continue, or Stop a Service

You can stop and start services on a Windows computer using the sc stop and sc start commands, respectively.

The following example stops and restarts the sshd service on Windows:

sc stop sshd
sc start sshd

When you stop and start a service, the service starts from scratch. When you pause a service, it retains all of its data.

When you restart a paused service with the continue command, the service begins right where it left off (note that some services are not pausable).

sc pause service-name
sc continue service-name

Configuring Startup Type of a Service

We use the sc config command to configure the startup type of a Windows service. The syntax of this command is as follows:

sc config Service-Name start=StartupType

The startup type can be either auto, demand, or disabled.

AutoThe service will automatically start when the system starts.
DemandThe service will start only when manually started or when called by another process.
DisabledDisabled - The service cannot be started. You have to change the startup type to either Auto or Demand before you can start a service that is set to Disabled.

The following command will configure the sshd service to automatically start on system startup:

sc config start=auto

Note that the administrative commands like sc config require you to launch CMD with administrative permissions (Run as administrator).