How to List All Services in a Batch Script
A Windows service is a background program that can start with the operating system and run independently of any user being logged on. For system administrators, getting a list of all installed services is a fundamental task for system audits, troubleshooting, or for finding the specific name of a service to be managed by a script.
This guide will teach you how to list all services using the two primary built-in Windows commands for this purpose: the modern and powerful sc.exe (Service Control) utility, and the script-friendly WMIC command. You will learn how to filter the output to find what you need and how to get both the service name and the display name.
The Core Command: sc query
The sc.exe (Service Control) utility is the definitive command-line tool for interacting with the Windows Service Manager. The query subcommand is used to list services and their status.
Syntax: To list all services, you must specify the type and state: sc queryex type=service state=all
queryex: The "extended" query that provides more detail.type=service: Restricts the list to actual services (as opposed to drivers, etc.).state=all: Shows all services, regardless of whether they are running or stopped.
This command produces a long, detailed list, with each service in its own multi-line block.
SERVICE_NAME: Spooler
DISPLAY_NAME: Print Spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
...
SERVICE_NAME: wuauserv
DISPLAY_NAME: Windows Update
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 1 STOPPED
...
The Scripting-Friendly Method: WMIC SERVICE
While sc query is very detailed, its multi-line format is difficult to parse in a script. For automation, the WMIC command is often the superior choice. It can return the information in a clean, table-based format.
Command: WMIC SERVICE GET Name,DisplayName,State,StartMode
SERVICE: The WMI class for installed services.GET ...: Specifies the properties you want to display in columns.
This produces a single, wide table that is much easier to read and parse.
DisplayName Name StartMode State
...
Print Spooler Spooler Auto Running
...
Windows Update wuauserv Manual Stopped
...
Basic Example: A Simple List of All Services
This script uses the recommended WMIC command to create a simple list.
@ECHO OFF
ECHO --- Listing All Installed Windows Services ---
ECHO This may take a moment...
ECHO.
WMIC SERVICE GET Name,DisplayName,State,StartMode
PAUSE
Filtering the Output to Find a Specific Service
The full list from either command is very long. The key to using them effectively is to pipe the output to a filter command like findstr.
Example: Finding a service by its Display Name
REM Use the detailed SC command to get all info for a specific service.
sc queryex type=service state=all | findstr /I /C:"Display Name To Find" -B -A 8
Example: Filtering the WMIC output (easier)
REM Use WMIC with a WHERE clause for server-side filtering (more efficient).
WMIC SERVICE WHERE "DisplayName LIKE '%%Windows%%'" GET Name,DisplayName,State
REM Or, use a client-side findstr for simplicity.
WMIC SERVICE GET Name,DisplayName,State | findstr /I "Windows"
Key Service Properties to Look For
When you list services, these are the most important pieces of information:
SERVICE_NAME(Namein WMIC): The short, internal name of the service. This is the name you must use in commands likesc stoporsc delete.DISPLAY_NAME(DisplayNamein WMIC): The long, user-friendly name you see in the Services GUI.STATE(Statein WMIC): The current status of the service (e.g.,RUNNING,STOPPED).START_TYPE(StartModein WMIC): How the service is started (Auto,Manual,Disabled).
Common Pitfalls and How to Solve Them
-
Administrator Rights: A standard user can list services, but the list may be incomplete, and detailed queries can fail. To get a complete and accurate view of all services on the system, you must run your script as an Administrator.
-
Service Name vs. Display Name: This is the number one source of errors. Scripts fail because they try to use the long "Display Name" in a command that requires the short "Service Name."
- Solution: Always use a query command first (
sc queryexorWMIC) to find the correct internalSERVICE_NAMEbefore you try to manage a service.
- Solution: Always use a query command first (
-
Output Overload: The full list of services is long.
- Solution: Pipe the output to
| moreto view it one page at a time, or pipe it to| findstrto filter for the specific service you need.
- Solution: Pipe the output to
Practical Example: A Service Audit Report Script
This script uses the powerful WMIC command to generate a CSV report of all services that are currently running. This is a common task for system auditing and security checks.
@ECHO OFF
SETLOCAL
SET "ReportFile=%USERPROFILE%\Desktop\Running_Services_Report.csv"
ECHO --- Service Audit Script ---
ECHO Generating a report of all running services...
ECHO Report will be saved to: "%ReportFile%"
ECHO.
REM --- Create the CSV Header ---
ECHO "DisplayName","Name","StartMode","State","PathName" > "%ReportFile%"
REM --- Use a FOR /F loop to process the WMIC output ---
REM We use a WHERE clause to filter for running services only.
FOR /F "skip=1 tokens=*" %%A IN ('WMIC SERVICE WHERE "State='Running'" GET DisplayName^,Name^,PathName^,StartMode /FORMAT:CSV') DO (
REM The output from WMIC CSV format is Node,Property1,Property2,...
REM We need to parse this to reorder it.
FOR /F "tokens=2-5 delims=," %%C IN ("%%A") DO (
ECHO "%%C","%%D","%%E","Running","%%F" >> "%ReportFile%"
)
)
ECHO [SUCCESS] Report created.
ENDLOCAL
Conclusion
Windows provides two primary tools for listing services, each with its own strengths.
sc queryexis excellent for getting highly detailed, multi-line information about a specific service.WMIC SERVICEis the superior and recommended method for scripting. It provides a clean, table-based output that is easy to filter and parse with aFOR /Floop.
By using WMIC to query and list services, you can create powerful and accurate automation scripts for system auditing, monitoring, and management.