Stopping and Starting Services with the net Command
A basic way to start and stop a service from the command prompt is with the net command. The basic syntax to start a service is
Similarly, the basic syntax to stop a service is
For example, if SRV records aren’t registered in DNS, you can stop and restart the netlogon service with the following commands:
net stop netlogon
net start netlogon
Tip
The netlogon service
registers SRV records on a DNS server. The SRV records are needed to
locate servers (such as domain controllers). If the SRV records aren’t
created, you can force their creation by stopping and restarting the
netlogon service.
Similarly, if a network is
using a Key Management Server (KMS) but the KMS SRV records aren’t
registered in DNS, you can run the following commands.
Command | Operating System |
---|
net stop slsvc
net start slsvc
| Use on Windows Server 2008 server hosting KMS. |
net stop sppsvc
net start sppsvc
| Use on Windows Server 2008 R2 server hosing KMS. |
The hardest part about running the net stop and net start commands is identifying the service name. One way is from the Services console. You can launch the Services console from the Administrative Tools menu, browse to any service, and double-click it to see the properties. Figure 1 shows the netlogon service open. Notice that the Service Name is Netlogon.
Tip
Some services (such as the netlogon service) have the same name used for both the Service Name and the Display Name; however, many services use different names. You must use the Service Name in the net stop and net start commands.
Manipulating Services with sc
You can also use the service controller (sc)
command to start, stop, and manipulate services from the command line.
This enables you to perform many of the same functions from the command
line as you can do through the Services console.
Some of the common functions are shown in the following table.
Command | Description |
---|
C:\>sc query
SERVICE_NAME: Netlogon
DISPLAY_NAME: Netlogon
TYPE : 20 WIN32_
SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,
PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
| Lists all running
services and drivers. The result on the left shows the results for a
single service (the netlogon service), but the actual output shows
details on all running services and drivers. The output can be quite
extensive.
Of course, you can capture the entire output with the redirect (>) symbol assc query > services.txt
Tip
The service name shows the name of the service that you can use in other commands.
|
sc query state= all | inactive
C:\>sc query state= all
C:\>sc query state= inactive
| Lists all services including services stopped, running, or paused.
Note
There is no space between state and = (state=), and there is a space between = and all (= all).
You can use state= inactive to list only services that are stopped or state= all to list all services, including those that are running and those that are stopped. |
sc query type= service | driver | all
C:\>sc query type= service
C:\>sc query type= driver
C:\>sc query type= all
| Lists all running services or drivers. Notice that there is no space between type and = (type=), and there is a space between = and service (= service).
You can also use type= driver to list drivers instead of services, or type= all to list both. |
Sc query service-name
C:\>sc query netlogon
SERVICE_NAME: Netlogon
DISPLAY_NAME: Netlogon
TYPE : 20 WIN32_
SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,
PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
| Lists
the details on a specific service. The example shows the details on the
netlogon service, but you can use the same command for any specific
service by specifying the name.
As a reminder, the service-name is the same name you can see in the SERVICE_NAME output from the sc query command. |
sc stop service-name
C:\>sc stop netlogon
| Stop a service. The example stops the netlogon service. You can substitute the service name for any service to stop it. |
sc start service-name
C:\>sc start netlogon
| You can start the service with the sc start command.
This example starts the netlogon service, but you can substitute the service name for any service to start it. |
sc pause service-name
C:\>sc pause netlogon
| Pauses the service.
Note
Not all services can be paused. If the service is listed as PAUSABLE (in the State property), it can be paused. If the service is listed as NOT_PAUSABLE, it cannot be paused.
|
sc continue service-name
C:\>sc continue netlogon
| You can restart a paused service with the continue command. |
Note
One drawback from stopping and starting services with the sc command is that it doesn’t let you know when the service stopped or started, like net stop and net start commands do. However, you can use the sc query service-name command to identify the current state of the service.