How to List Installed Printers in a Batch Script
Whether you are writing a script to manage printer settings, set a default printer, or simply audit the hardware available on a system, you first need a way to get a list of all installed printers. Windows provides several built-in command-line tools that can query the printing subsystem and provide this information.
This guide will teach you the modern, recommended method for listing printers using the powerful WMIC command, which provides detailed and script-friendly output. We will also cover the legacy prncnfg.vbs script for comparison and show you how to parse the WMIC output to use the printer names in your automation.
The Challenge: Finding Printer Information
Printer information is managed by the Windows Print Spooler service. While you can view it in the Control Panel, a script needs to query this service directly. The WMIC utility provides the cleanest and most direct interface to do this without complex parsing.
Method 1 (Recommended for Scripting): Using WMIC
The WMIC (Windows Management Instrumentation Command-line) utility is the standard tool for querying system hardware and software, including printers. The PRINTER alias gives us direct access to all installed printer queues.
Command: WMIC PRINTER GET Name,Default,PortName
PRINTER: The WMI class for installed printer devices.GET ...: Specifies the properties you want to display.
This command produces a clean, well-structured table that is perfect for both human reading and script parsing. The Default property is a simple TRUE or FALSE.
Default Name PortName
TRUE Microsoft Print to PDF PORTPROMPT:
FALSE HP LaserJet Pro (Network) IP_192.168.1.100
FALSE Microsoft XPS Document Writer PORTPROMPT:
FALSE Fax SHRFAX:
Method 2 (Legacy): Using the prncnfg.vbs Script
Windows also includes a legacy VBScript tool, prncnfg.vbs, which can be used to manage printers. While still functional, its output is less structured and generally considered inferior to WMIC for modern scripting.
Command: cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -l
-l: The switch to list all printers.
The output is less structured and harder to parse reliably.
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Printers:
HP LaserJet Pro (Network)
Fax
Microsoft XPS Document Writer
Microsoft Print to PDF
Parsing the WMIC Output to Process Each Printer
The real power of the WMIC method is the ability to use its output in a FOR loop, allowing you to perform an action for each installed printer.
This script iterates through each printer and echoes its name.
@ECHO OFF
ECHO --- Iterating through all installed printers ---
ECHO.
REM The 'skip=1' ignores the header line of the WMIC output.
FOR /F "skip=1 tokens=*" %%P IN ('WMIC PRINTER GET Name') DO (
IF NOT "%%P"=="" ECHO Found Printer: "%%P"
)
The IF NOT "%%P"=="" is used to filter out extra blank lines that WMIC sometimes produces.
Output:
--- Iterating through all installed printers ---
Found Printer: "Microsoft Print to PDF "
Found Printer: "HP LaserJet Pro (Network) "
Found Printer: "Microsoft XPS Document Writer "
Found Printer: "Fax "
Key WMIC PRINTER Properties Explained
You can GET many useful properties from the PRINTER class:
Name: The friendly name of the printer as seen in Control Panel.Default: A boolean (TRUE/FALSE) indicating if it's the default printer.PortName: The port the printer is connected to (e.g.,USB001,IP_192.168.1.100).DriverName: The name of the printer driver being used.Shared: A boolean indicating if the printer is shared on the network.WorkOffline: A boolean indicating if the printer is set to work offline.Status: The current status of the printer (e.g.,Idle,Printing).
Common Pitfalls and How to Solve Them
-
WMICOutput Quirks:WMICoften pads its output with extra spaces and can include trailing carriage returns. This can break string comparisons.- Solution: When capturing a value into a variable, a simple "cleaning"
FORloop is the best practice.FOR /F "skip=1 tokens=*" %%P IN (...) DO (
SET "PrinterNameRaw=%%P"
CALL :CleanVar PrinterNameRaw
...
)
...
:CleanVar
FOR /F "tokens=*" %%V IN ("!%1!") DO SET "%1=%%V"
GOTO :EOF
- Solution: When capturing a value into a variable, a simple "cleaning"
-
Running as Standard User vs. Administrator: A standard user can typically list their own installed printers. However, for a complete list of all printers on a system, especially those installed for all users, it is more reliable to run the script as an Administrator.
Practical Example: A Script to Find a Specific Network Printer
This script audits a system to check if a specific, required network printer has been installed.
@ECHO OFF
SETLOCAL
SET "RequiredPrinter=HP LaserJet Pro (Network)"
SET "IsInstalled=0"
ECHO --- Checking for required printer: "%RequiredPrinter%" ---
ECHO.
FOR /F "skip=1 tokens=*" %%P IN ('WMIC PRINTER GET Name') DO (
REM Clean the printer name from WMIC's output
SET "CurrentPrinter=%%P"
FOR /F "tokens=*" %%C IN ("!CurrentPrinter!") DO SET "CurrentPrinter=%%C"
IF /I "!CurrentPrinter!"=="%RequiredPrinter%" (
SET "IsInstalled=1"
GOTO :Found
)
)
:Found
IF %IsInstalled% EQU 1 (
ECHO [SUCCESS] The required printer is installed.
) ELSE (
ECHO [FAILURE] The required printer is NOT installed.
)
ENDLOCAL
This script requires DelayedExpansion (!Var!) for the cleaning loop to work correctly inside the main FOR loop.
Conclusion
While Windows provides a couple of ways to get a list of installed printers, they are not created equal for scripting.
- The legacy
prncnfg.vbsscript works but provides unstructured output that is difficult to parse reliably. - The
WMIC PRINTERcommand is the overwhelmingly superior and recommended method. It provides clean, structured, and detailed information that is perfect for automation.
By using WMIC and parsing its output with a FOR /F loop, you can write powerful scripts to audit, manage, and configure printers in any Windows environment.