Search code examples
batch-filedefaultprinters

Show default printer's properties and preferences


I'm trying to create batch file which opens printer properties for the default printer, but I get an error. I tried using

rundll32 printui.dll,PrintUIEntry /e /n "printername"

but it opens properties only if you will write a printer name with your hand.

I wanted to know if there is a similar cmd command which shows printer properties and printer preferences for the default printer, without writing a printer name.

I tried using rundll32 printui.dll,PrintUIEntry /e /n "%printer_name%" but it gave error.


Solution

  • You can list the printers and find the default, then initiate the command.:

    for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do echo "%%~b"
    

    The above simply lists the default, where the below code will do what you manually typed in your example:

    for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do rundll32 printui.dll,PrintUIEntry /e /n %%~b
    

    you might experience unwanted spaces in the code, then just assign a variable and replace multiple whitespace with none.

    for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do set printer=%%b
    rundll32 printui.dll,PrintUIEntry /e /n "%printer:   =%"
    

    Edit.

    for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do set printer=%%b
    Set "printer=%printer:   =%"
    rundll32 printui.dll,PrintUIEntry /e /n "%printer:  =%"