SC Command: Control Windows Services from the Command Line

Remote Service Management via Command Line
As my involvement in Information Technology has grown, I've increasingly focused on the monitoring and status verification of services operating on computers throughout the organization.
The conventional method for service management is widely utilized due to its familiarity and relative simplicity.
This typically involves navigating to Administrative tools or the Control Panel, locating the Services utility, and performing the necessary actions.
Managing Services on Remote Machines
To administer services running on a different computer or server within the network, accessing Computer Management is required.
From there, a connection to the remote machine must be established before service management can proceed.
This approach is perfectly valid and remains a staple for system administrators globally when maintaining enterprise infrastructure.
The Power of the Command Line
However, consider the efficiency gained by being able to monitor, halt, and initiate services with a single command entered at the prompt.
This offers a streamlined alternative to the graphical user interface methods.
Command-line service management provides a powerful and flexible way to interact with system services.
It allows for scripting and automation, enhancing administrative capabilities.
Ultimately, this method can significantly reduce the time and effort required for routine service administration tasks.
Managing Services via the Command Line
Occasionally, it becomes necessary to halt services on a client machine to facilitate software reinstallation. Alternatively, restarting services on a server might be required to resolve functionality issues with specific software.
Traditionally, service management on client computers within a network has been performed using the standard Services utility. This refers to the Services tool accessible through the Administrative Tools area of the control panel.
Within Admin Tools, users can directly launch the Services tool or opt to open Computer Management for access to different computers on the network.
To manage a remote computer, select "Connect to Another Computer" from the Action menu and input the network name of the target machine.
Following this connection, the Services tool becomes available for use.
A More Efficient Approach to Service Management
However, a more streamlined method exists – utilizing the "SC" command.
Those familiar with the NET command will find the SC command conceptually similar. Notably, SC possesses the additional capability of creating services, alongside its functions of monitoring, stopping, and starting them. Furthermore, the SC command can be executed against remote computers across the network, provided administrative privileges are held.
Executing an SC query on a computer reveals a comprehensive list of installed services and their current running status. Issuing the command "SC \\**computer-name** query |more" generates output as illustrated.
This output details the service state, service type, and other relevant parameters. For the purpose of this discussion, we will focus primarily on the service state.
To display only services that are currently inactive (stopped), the command "SC \\**computer-name** query state= "inactive" |more" can be used.
The "|more" component of the command pauses the output after each screenful, enabling scrolling for easier review.
If a specific service's status is required, the command "SC \\**computer-name** query **service-name**" can be employed.
This will report the status of only the designated service, excluding all others. To remotely stop a service, simply use the command "SC \\**computer-name** stop **service-name**"
The system will indicate a "STOP-PENDING" state, which will transition to a stopped status upon subsequent querying.
Service initiation is achieved by using the same command, substituting "stop" with "start".
Developing a Script for Querying, Stopping, or Starting Services
Having established the fundamentals, a script can be developed to stop or start any desired service without needing to recall the precise command syntax. This can be accomplished through a Windows Script, as shown below.
Upon execution, this script prompts for the service name and the desired action – stop or start.
The ">> c:\temp\results.txt" directive redirects the stop and start results, along with any errors, to a text file for review.
After running the script, a quick query of the service was performed to confirm its status before and after script execution.
As demonstrated, the service previously running – helpsvc – was successfully stopped by the script.
For enhanced functionality, the script could be extended to output a list of all installed services on the computer to a text file for review prior to selecting a service to stop or start. The command for this would be "sc \\" & strComputer & " query > c:\temp\services.txt".
In conclusion, the SC command offers a potent and efficient method for managing services on any computer. Coupled with Windows Scripting skills, the process can be further automated, increasing productivity.
Do you foresee the SC command being beneficial in your workflow? What are your thoughts on an automated script utilizing this command? Share your insights and ideas in the comments section below.
Image Credit: Shutterstock
Related Posts

Touchscreen on Windows PC: Do You Need It?

Find Lost Windows or Office Product Keys - Easy Guide

Windows 10 Resetting Settings: Why It Happens & How to Fix

Monitor FPS in UWP Games on Windows 10 - A Simple Guide
Remove 'Get Windows 10' Icon & Stop Upgrade Notifications
