Service Management With Windows Sc From Command Line – POFTUT

Service Management With Windows Sc From Command Line


Operating systems run services to server operating system or user level features. These windows services generally starts in the startup and stopped at the shutdown. But some time we need to start service after the start or a configuration change.

Windows provides different tools to manage services. We have all ready looked the native Powershell service management tools following tutorial.

Service Management With Windows Powershell From Command Line

Help

Detailed help about sc command can be get with /? option like below.

$ sc /?
Help
Help

Syntax

sc command syntax is similar to the most of the windows command. First we specify server names if we want to run service command remote systems and then provide real command to operate on service. After those we specify service name and other options.

sc <server> [command] [service name] <option1> <option2>...

Naming Service

There are two identifier to name services. SERVICE_NAME is real name where we use for related service operations and will be used for identifier. DISPLAY_NAME is like a tag and used to provide more readable and understandable service names. In the following example we should use Appinfo for service operations.

SERVICE_NAME: Appinfo
DISPLAY_NAME: Application Information

Start Service

Services should be started in order serve. There are a lot of services in a windows operating systems. We will use start command in order to start windows service. Some services can be depended other services. In this situations we should start first dependency services.

In this example we will start the service named ProtectedStorage .

$ sc start ProtectedStorage
Start Service
Start Service

If the service starts without a problem it will print the status of the service. The STATE line shows the service is pending for start.

LEARN MORE  How To Start, Stop, Restart Networking On Linux?

Stop Service

Stopping a windows service is very similar to starting it. We will just change the start command with stop command. In this example we will stop the service named ProtectedStorage where we have started it in previous step.

$ sc stop ProtectedStorage
Stop Service
Stop Service

Display Detailed Service Status

Detailed information about a service can be displayed with query command by providing the service name. In this example we display information about ProtectedStorage service.

$ sc query ProtectedStorage
Display Detailed Service Status
Display Detailed Service Status

This command output will provide following information about the service.

  • SERVICE_NAME
  • TYPE line shows service type
  • STATE line shows current status of service like STOPPED , RUNNING , etc.
  • WIN32_EXIT_CODE line shows last stop event exit code
  • SERVICE_EXIT_CODE
  • CHECKPOINT
  • WAIT_HINT

List All Services

There is a lot of service in a default Windows installation. After the installation 3 party applications may add new services too. All of these services can be listed with query command and state=all options like below.

$ sc query state= all
List All Services
List All Services

List Only Running Services

Previous example lists  all services those running or stopped. We may interested with only running services. If we provide no option to the  query command it will only print running services by default.

$ sc query

Restart Service

Services have configurations and these configurations can be changed during they are running. Or some services may start work incorrectly. In this situations restart services is the best way to make it work and apply new service configuration.

$ sc stop ProtectedStorage
$ sc start ProtectedStorage

Pause Service

A service can be paused without loosing its session related information and data. And then this service can be resumed too. In order to pause a service the service should support pausing. In this example  we will pause ProtectedStorage service.

$ sc pause ProtectedStorage

Resume or Continue Service

We will resume and continue an all ready paused service with continue command like below.

$ sc continue ProtectedStorage

Leave a Comment