How can I get the name of the default printer on my machine through the Windows command line?
4 Answers
Microsoft Windows XP comes with a VBS script to manage local and network printers from the command line:
Get the default printer details from command line:
cscript C:\windows\system32\prnmngr.vbs -g
Get the list of printers added to the system from Windows command line:
cscript C:\windows\system32\prnmngr.vbs -l
Set default printer from windows command line:
cscript C:\windows\system32\prnmngr.vbs -t -p "\Servername\printername"
Official documentation and more usage examples can be found at:
Basic classical scripts are often more practical than vbs or powershell scripts: there are no dependencies nor prerequisites to check, just put it in a cmd file... I would rather use this command on W10 (should work on Win7 as well but I didn't test):
for /f "tokens=2 delims==" %%A in ('wmic.exe printer WHERE default^=TRUE get name /VALUE') do (set "default_printer=%%A")
As a result, you get the default printer in the environment variable %default_printer%
The other proposed solution (based on registry reading) is not properly working: if you change the default printer and call again the script, the modification is not taken immediately into account in registry (maybe it would after next reboot). But this one works.
Using a batch file:
@echo off
::Get printer CLSID
for /f %%a in ('reg query HKCU\Printers\Defaults') do (set regkey=%%a)
::Get printer name from the previous CLSID
for /f "tokens=3*" %%a in ('reg query %regkey%') do (set printername=%%a %%b)
echo Printer name is: %printername%
I wish that could help you
In PowerShell 5.1+, you could use the following:
Get-CimInstance Win32_Printer | ? Default | select Name