programming4us
programming4us
DESKTOP

Windows Server 2008 : Stopping and Starting Services with the net Command, Manipulating Services with sc

9/20/2012 12:59:02 AM

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

net start service-name

Similarly, the basic syntax to stop a service is

net stop service-name

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.

CommandOperating 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.

Figure 1. Viewing properties of a service


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.

CommandDescription
 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.

Other  
  •  Windows Server 2008 and Windows Vista : Altering Default GPO Processing and Inheritance (part 2) - Security Filtering, WMI Filters, Group Policy Preferences
  •  Windows Server 2008 and Windows Vista : Altering Default GPO Processing and Inheritance (part 1) - Block Policy Inheritance, Enforce
  •  Windows Server 2008 and Windows Vista : Group Policy Processing - Version Checking During Updates
  •  Windows 7 : Syncing with Network Files (part 2) - Dealing with Conflict
  •  Windows 7 : Syncing with Network Files (part 1) - Using Sync Center, Settings for offline files
  •  Windows Vista : Deploying Applications - Choosing a Deployment Strategy
  •  Windows Vista : Deploying Applications - Planning Deployment
  •  Windows Server 2003 : Active Directory - Understanding Directory Replication (part 3) - Spanning Trees and Site Links
  •  Windows Server 2003 : Active Directory - Understanding Directory Replication (part 2) - Update Sequence Numbers
  •  Windows Server 2003 : Active Directory - Understanding Directory Replication (part 1) - Time Synchronization, Replication Topologies, Handling Update Conflicts
  •  
    video
     
    Video tutorials
    - How To Install Windows 8

    - How To Install Windows Server 2012

    - How To Install Windows Server 2012 On VirtualBox

    - How To Disable Windows 8 Metro UI

    - How To Install Windows Store Apps From Windows 8 Classic Desktop

    - How To Disable Windows Update in Windows 8

    - How To Disable Windows 8 Metro UI

    - How To Add Widgets To Windows 8 Lock Screen
    programming4us programming4us
    programming4us
     
     
    programming4us