


How to Manage Windows Services via Command Line - Make Tech Easier
May 26, 2025 am 01:06 AMI constantly seek effective methods to handle system tasks directly from the terminal, even on a Windows system. Windows services operate in the background, ensuring the smooth operation of the system and applications. Instead of navigating through the Services Manager, I prefer managing these services using command-line tools. This guide will delve into these techniques, demonstrating how you can control Windows services right from the command line.
Table of Contents
- Using sc.exe to Manage Windows Services
- Utilizing the Net Command for Service Management
- Leveraging PowerShell Cmdlets for Service Control
- Automating Service Management Tasks
Using sc.exe to Manage Windows Services
sc.exe is a command-line utility built into Windows, designed for managing services. It allows you to configure, query, and control services directly from the command line, providing full control over Windows services without the need for the graphical Services Manager.
Checking service status with sc
To check the status of a specific service, you can use the sc query serviceName
command. For instance, executing sc query MySQL80
will provide details about the MySQL80 service, including its current state:
In this case, MySQL is currently not running on the system.
Starting a service with sc
To initiate a service using sc.exe, you can use the sc start ServiceName
command. For example, to start the MySQL80 service, you would run sc start MySQL80
. To confirm that the service has started successfully, you can check its status again with sc query MySQL80
:
Stopping a service with sc
If you need to stop a service to free up system resources, you can use the sc stop ServiceName
command. For example, to stop MySQL, you would execute sc stop MySQL80
, and then verify its status with sc query MySQL80
:
Creating a new service with sc
You can create a new service using the sc create
command, specifying the service name, executable path, and startup type. For example, to create a service named "mte" that starts automatically at boot, you would type:
<code>sc create mte binPath= "C:\Users\HP\Desktop\Examples\Service.exe" start= auto</code>
Updating a service with sc
To configure an existing service, you can use the sc config
command. For instance, to change the startup type to manual, you would run:
<code>sc config serviceName start= demand</code>
Deleting a service with sc
To permanently remove a service from Windows that is no longer needed, you can use the command:
<code>sc delete srviceName</code>
Utilizing the Net Command for Service Management
The net
command in Windows allows you to manage services directly from the command line, offering options to start, stop, pause, resume, and query services without the need for the graphical Services Manager.
Starting and stopping service with net command
To start or stop Windows services, you can use the net start serviceName
and net stop serviceName
commands, respectively:
Pausing and resuming services with net command
Some services support pausing and resuming instead of a complete stop. In such cases, you can use the net pause ServiceName
and net continue ServiceName
commands, respectively:
Checking service status with net command
While the net
command does not directly check the status of a specific service, you can use it in conjunction with the findstr
command to filter results. For example, to check if a specified service is running, you would type:
<code>net start | findstr "ServiceName"</code>
If the service is running, the command will return its name; otherwise, there will be no output.
Manage services remotely with net command
You can manage services on remote computers using the net
command by specifying the computer name. For instance, to start or stop services on a remote computer, you would use net start ServiceName /S RemotePC
and net stop ServiceName /S RemotePC
, respectively.
Leveraging PowerShell Cmdlets for Service Control
PowerShell provides advanced control over Windows services with built-in cmdlets such as Get-Service
, Start-Service
, Stop-Service
, and Restart-Service
. These cmdlets allow you to check the status of a service, start or stop it, and even restart it when necessary.
PowerShell cmdlets offer detailed output, including service status, display name, and dependent services. They support scripting and automation, making them ideal for efficiently managing multiple services.
PowerShell's flexibility and powerful features make it a preferred tool for administrators managing Windows services.
Getting service status with cmdlets
To get details about a specific service, you can use the Get-Service -Name ServiceName
cmdlet. For example, to check the status of the MySQL80 service, you would run:
<code>Get-Service -Name MySQL80</code>
Querying services with PowerShell cmdlets
You can use the Get-Service
command to query services based on specific criteria. For instance, to retrieve all currently running services, you would run:
<code>Get-Service | Where-Object {$_.Status -eq 'Running'}</code>
Starting and Stopping Services with PowerShell cmdlets
To start or stop a specific service, you can use the Start-Service
and Stop-Service
cmdlets, respectively. For example, to manage the MySQL80 service, you would use:
<code>Start-Service -Name MySQL80 Stop-Service -Name MySQL80 Get-Service -Name MySQL80</code>
Changing service startup type with PowerShell cmdlets
PowerShell cmdlets allow you to update the service startup type. For example, to configure a service to start automatically, manually, or be disabled, you would run:
<code>Set-Service -Name ServiceName -StartupType Automatic Set-Service -Name ServiceName -StartupType Manual Set-Service -Name ServiceName -StartupType Disabled</code>
These cmdlets help administrators manage service behavior efficiently, ensuring essential services start as needed while preventing unnecessary ones from running.
Managing remote services with cmdlets
PowerShell also supports managing services on remote computers by specifying the names of the remote computers. For example, to retrieve the status of a service on a remote computer named RemotePC, you would use:
<code>Get-Service -Name ServiceName -ComputerName RemotePC</code>
Similarly, to restart a service on a remote computer, you would run:
<code>Restart-Service -Name ServiceName -ComputerName serviceName</code>
Remote service management requires appropriate permissions and PowerShell remoting to be enabled.
Automating Service Management Tasks
PowerShell scripts can automate service management, allowing you to monitor and control Windows services without manual intervention. For example, the following script checks whether the MySQL80 service is running and restarts it if it is stopped:
<code>$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." }</code>
To enable script execution, you must first run:
<code>Set-ExecutionPolicy RemoteSigned</code>
Then, navigate to the script location and execute the .\\serviceScript.ps1
command to run the script:
Managing Windows services from the command line provides complete control without relying on the graphical Services Manager. Whether you use sc.exe
, net
, or PowerShell cmdlets, each method offers efficient ways to start, stop, and configure services.
PowerShell's scripting capabilities make automation straightforward, allowing you to monitor and manage services seamlessly. By mastering these tools, you can troubleshoot issues, optimize system performance, and ensure critical services run smoothly.
For more ways to optimize your Windows system and troubleshoot common issues, explore these guides on resolving Windows problems and enhancing your PC's performance.
The above is the detailed content of How to Manage Windows Services via Command Line - Make Tech Easier. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

If you're having trouble reading your desktop icons' text or simply want to personalize your desktop look, you may be looking for a way to change the font color on desktop icons in Windows 11. Unfortunately, Windows 11 doesn't offer an easy built-in

Fixed Windows 11 Google Chrome not opening Google Chrome is the most popular browser right now, but even it sometimes requires help to open on Windows. Then follow the on-screen instructions to complete the process. After completing the above steps, launch Google Chrome again to see if it works properly now. 5. Delete Chrome User Profile If you are still having problems, it may be time to delete Chrome User Profile. This will delete all your personal information, so be sure to back up all relevant data. Typically, you delete the Chrome user profile through the browser itself. But given that you can't open it, here's another way: Turn on Windo

When Windows cannot detect a second monitor, first check whether the physical connection is normal, including power supply, cable plug-in and interface compatibility, and try to replace the cable or adapter; secondly, update or reinstall the graphics card driver through the Device Manager, and roll back the driver version if necessary; then manually click "Detection" in the display settings to identify the monitor to confirm whether it is correctly identified by the system; finally check whether the monitor input source is switched to the corresponding interface, and confirm whether the graphics card output port connected to the cable is correct. Following the above steps to check in turn, most dual-screen recognition problems can usually be solved.

Mini PCs have undergone

Have problems uploading files in Google Chrome? This may be annoying, right? Whether you are attaching documents to emails, sharing images on social media, or submitting important files for work or school, a smooth file upload process is crucial. So, it can be frustrating if your file uploads continue to fail in Chrome on Windows PC. If you're not ready to give up your favorite browser, here are some tips for fixes that can't upload files on Windows Google Chrome 1. Start with Universal Repair Before we learn about any advanced troubleshooting tips, it's best to try some of the basic solutions mentioned below. Troubleshooting Internet connection issues: Internet connection

When encountering the problem of printing task stuck, clearing the print queue and restarting the PrintSpooler service is an effective solution. First, open the "Device and Printer" interface to find the corresponding printer, right-click the task and select "Cancel" to clear a single task, or click "Cancel all documents" to clear the queue at one time; if the queue is inaccessible, press Win R to enter services.msc to open the service list, find "PrintSpooler" and stop it before starting the service. If necessary, you can manually delete the residual files under the C:\Windows\System32\spool\PRINTERS path to completely solve the problem.

To run command prompts as administrator, the most direct way is to search through the Start menu and right-click "Run as administrator"; secondly, use the Win X shortcut menu to select "Command Prompt (Administrator)" or "Windows Terminal (Administrator)"; you can also open the run window through Win R and enter cmd and press Ctrl Shift Enter to force running as administrator; in addition, you can set shortcut properties to achieve automatic running as administrator. All the above methods require administrator permission and confirmation through UAC. Pay attention to security risks during operation.
