
Many system administrators and IT professionals are constantly seeking efficient ways to conduct system tasks directly from the command line, particularly within the Windows environment. Windows services play a critical role in maintaining seamless operations for both the system and applications. Instead of relying on graphical interfaces like the Services Manager, managing Windows services via the command line offers greater flexibility and speed. This guide delves into various command-line tools to manage Windows services directly from your terminal.
1. Manage Windows Services with sc.exe
The sc.exe
command-line utility is an invaluable tool that empowers users to manage Windows services. Through this utility, you can configure, monitor, and control services seamlessly via the command line, without needing to utilize the graphical Services Manager.
Check Service Status Using sc
To check the status of a particular service, utilize the sc query serviceName
command. For example:
sc query MySQL80
This command will reveal details about the state of the MySQL80 service:

As shown, this indicates that MySQL is currently inactive on the machine.
Start a Service with sc
To activate a specific service, use the command:
sc start MySQL80
After starting the service, you can confirm its status with:
sc query MySQL80

Stop a Service Using sc
If you need to halt a service to reclaim system resources, execute:
sc stop MySQL80
Confirm this action by running:
sc query MySQL80

Create a New Service with sc
To establish a new service, the syntax is:
sc create mte binPath="C:\Users\HP\Desktop\Examples\Service.exe"start= auto

Update an Existing Service with sc
Modify an existing service’s configuration using:
sc config serviceName start= demand

Delete a Service with sc
To remove a service completely, run:
sc delete serviceName

2. Managing Windows Services with the net
Command
The net
command enables users to manage Windows services without needing the graphical interface. It permits starting, stopping, pausing, resuming, and querying services efficiently.
Start and Stop Services with net
Commands
Execute the following commands to manage services:
net start serviceName
net stop serviceName

Pause and Resume Services
For services that allow it, you can pause and resume operations using:
net pause ServiceName
net continue ServiceName

Check Service Status with net
Though net
does not directly report service status, you can use:
net start | findstr "ServiceName"

This command will return the service name if it is running; no output means the service isn’t active.
Remote Service Management
Manage services on remote machines using:
net start ServiceName /S RemotePC
net stop ServiceName /S RemotePC
3. Manage Windows Services with PowerShell Cmdlets
PowerShell introduces a higher level of control with cmdlets designed for service management. Utilizing cmdlets like Get-Service
, Start-Service
, Stop-Service
, and Restart-Service
, users can execute tasks with even greater functionality.
Check Service Status with Cmdlets
To inspect a service’s status, use:
Get-Service -Name MySQL80

Querying Services with PowerShell
Utilize cmdlets to filter services based on their state. For instance, to list running services:
Get-Service | Where-Object { $_. Status -eq 'Running' }

Manage Services with PowerShell Cmdlets
Start and stop services using:
Start-Service -Name MySQL80
Stop-Service -Name MySQL80
And check the status again:
Get-Service -Name MySQL80

Changing Service Startup Types with PowerShell Cmdlets
To modify a service’s startup type, you can set it to automatic, manual or disabled with:
Set-Service -Name ServiceName -StartupType Automatic
Set-Service -Name ServiceName -StartupType Manual
Set-Service -Name ServiceName -StartupType Disabled
This allows seamless management tailored to your operational preferences.
Remote Management with PowerShell
To check or control services on a remote machine, utilize:
Get-Service -Name ServiceName -ComputerName RemotePC
This capability is particularly useful for managing services in multi-computer environments.
4. Automate Service Management Tasks
PowerShell’s scripting abilities empower administrators to automate service management, minimizing manual intervention. For instance, you can create a script that consistently monitors the status of a service and restarts it if it goes down.
Example of an Automation Script
Consider a script that checks whether the MySQL80 service is operational and restarts it if not:
$serviceName = "MySQL80" $service = Get-Service -Name $serviceName if ($service. Status -ne "Running") { Restart-Service -Name $serviceName -Force Write-Output "$serviceName was stopped and has been restarted." } else { Write-Output "$serviceName is already running." }
Running scripts is restricted by default in Windows. Thus, to enable execution, execute:
Set-ExecutionPolicy RemoteSigned

To run the created script, navigate to its location and execute:
.\serviceScript.ps1

By harnessing the power of command line tools like sc.exe
, net
, and PowerShell, you gain complete authority over Windows services without having to employ the graphical Services Manager. Each method provides effective means for starting, stopping, and configuring services. Furthermore, PowerShell’s scripting capabilities facilitate extensive automation, ensuring critical services remain operational while enhancing system performance and reliability.
Frequently Asked Questions
1. What are Windows services?
Windows services are background processes that run independently of user sessions, providing essential functionalities for the operating system and applications.
2. How do I know which services are running on my Windows machine?
You can find out which services are running by using commands such as sc query
or Get-Service
in PowerShell.
3. Can I manage services remotely using command line?
Yes, you can manage services on remote computers using the net
command combined with the /S
switch or through PowerShell cmdlets with the -ComputerName
parameter.
Leave a Reply ▼