SC - CMD
Overview
The SC
command in Windows Command Prompt is a versatile tool used for communicating with the Service Control Manager and services. It allows users to perform tasks related to Windows services such as creating, starting, stopping, configuring, or deleting services. The command is most effective in administrative scripts, system administration, and automated service management tasks.
Syntax
The basic syntax for the SC
command is as follows:
SC [servername] command [service_name] [options]
- [servername]: Specifies the target server. Use
\\ServerName
to target a remote server, or omit for the local machine. - command: Specifies the action to perform, e.g.,
query
,start
,stop
,create
. - [service_name]: Specifies the service on which to execute the command.
- [options]: Additional parameters depending on the specific command.
Options/Flags
- query: Displays the status for a service, or enumerates the status for types of services.
- create: Creates a new service entry in the Service Control Manager.
- delete: Deletes a service (must be stopped first).
- start: Starts a service.
- stop: Stops a service.
- config: Changes the configuration of a service (e.g., start type, dependencies).
Each flag can have additional sub-options that modify its behavior or provide more detailed input.
Examples
-
Query the status of a specific service:
SC query "ExampleService"
-
Start a service:
SC start "ExampleService"
-
Stop a service:
SC stop "ExampleService"
-
Create a new service:
SC create "NewService" binPath= "C:\path\to\service.exe"
-
Delete an existing service:
SC delete "NewService"
Common Issues
- Permission Errors: Users might encounter permission issues if they attempt to manipulate a service without proper administrative privileges. Ensure that you are running the Command Prompt as an administrator.
- Incorrect Syntax: The
SC
command is syntax-sensitive; incorrect spacing or wrong order of options can lead to errors. Double-check the command structure if unexpected behavior occurs.
Integration
SC
can be integrated with other CMD commands or batch scripts for more powerful automations. For example, you can create a script to check if a service is running and start it if it’s not:
SC query "ExampleService" | find "RUNNING"
IF %ERRORLEVEL% NEQ 0 SC start "ExampleService"
Related Commands
- Net Start/Stop: Commands that can also be used to start or stop services.
- Tasklist / Taskkill: Handy for managing running processes linked to services.
For further information, refer to Microsoft’s official documentation on Service Control Manager commands and SC.