\\ Amazon パソコン・周辺機器 クーポンをチェックしよう!! //

How to Use the sc.exe Command for Managing Windows Services

The sc.exe (Service Control) command is a powerful tool that allows administrators to manage Windows services from the command line. With this command, you can create, configure, delete, start, stop, and query services, making it an essential tool for IT professionals who need to manage Windows services efficiently across multiple machines or networks.

目次

What is the sc.exe Command?

The sc.exe command is a Windows utility that allows users to manage services via the command line. It provides comprehensive control over services, enabling tasks such as service creation, modification, deletion, and querying. This tool is especially useful for system administrators who manage multiple services across networks or machines and need to automate service management tasks.

Key Uses of the sc.exe Command

  • Service Creation and Deletion: Create new services or remove unneeded ones.
  • Service Configuration: Modify existing service settings such as startup types or binary paths.
  • Service Status Monitoring: Check the current state (running, stopped, paused) of services.
  • Service Start/Stop: Easily start, stop, or restart services through the command line.

How to Use the sc.exe Command

The sc.exe command can be used with various subcommands to manage services effectively. Below is the basic syntax.

Basic Syntax

sc.exe [subcommand] [service name] [options]

How to Configure Services Using sc.exe config

The sc.exe config command allows you to modify the settings of an existing service.

Syntax

sc.exe config <service name> <options>
OptionDescription
start=Defines how the service starts: auto, demand, or disabled.
binpath=Specifies the executable path for the service.
displayname=Sets the display name for the service.
obj=Specifies the account under which the service runs.

Example 1: Set a Service to Start Automatically

sc.exe config MyService start=auto

Explanation: This command sets MyService to start automatically at boot.

Example 2: Change the Binary Path for a Service

sc.exe config MyService binpath="C:\Program Files\MyService\myservice.exe"

Explanation: Updates the binary path for MyService to point to a new executable file.

How to Create Services Using sc.exe create

The sc.exe create command is used to create a new service on a Windows system.

Syntax

sc.exe create <service name> binpath="<path to executable>" [options]
OptionDescription
binpath=Specifies the path to the service’s executable.
start=Defines the service start type: auto, demand, or disabled.

Example: Create a New Service

sc.exe create MyNewService binpath="C:\Program Files\MyNewService\service.exe" start=auto

Explanation: Creates a new service called MyNewService and sets it to start automatically.

How to Delete Services Using sc.exe delete

The sc.exe delete command is used to remove an existing service from the system.

Syntax

sc.exe delete <service name>

Example: Delete a Service

sc.exe delete MyService

Explanation: Deletes the MyService from the system.

How to Query Services Using sc.exe query

The sc.exe query command lets you check the current status of services, including whether they are running, stopped, or paused.

Syntax

sc.exe query <service name>

Example 1: Query the Status of a Specific Service

sc.exe query MyService

Explanation: Displays the current status of MyService.

Example 2: Query the Status of All Services

sc.exe query state=all

Explanation: Lists the status of all services on the system.

Practical Use Cases for the sc.exe Command

  1. Automated Service Monitoring and Management: Use scripts that leverage the sc.exe command to periodically monitor and control the state of critical services.
  2. System Troubleshooting: When services malfunction, the sc.exe query command helps diagnose the issue by displaying service states, errors, and potential conflicts.
  3. Batch Management of Services: Combine sc.exe commands in batch files to start or stop multiple services at once, or to configure them across many machines in a network environment.

Precautions When Using the sc.exe Command

  • Administrator Privileges: To manage services using sc.exe, you need to run the command prompt with administrative privileges. Right-click the command prompt and select “Run as administrator.”
  • Service Name Accuracy: Ensure that the service names are entered correctly to avoid inadvertently altering or deleting important system services.

Conclusion

The sc.exe command is a highly useful tool for managing Windows services through the command line. It enables administrators to automate service management tasks, such as service creation, modification, deletion, and status checking, improving the efficiency of system management. Whether you’re managing services for a single machine or across a network, sc.exe simplifies Windows service management and troubleshooting.

Tamaglo

Thank you for reading!

Comments

To comment

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here

目次