1

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.

laniakea
  • 81
  • 1
  • 11
  • The error message is: printing preferences cannot be displayed, operation could not be completed 0x000007c – laniakea Dec 02 '19 at 09:14

1 Answers1

3

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:  =%"
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • I keep getting error messages, the only time it works is when Fax is set as default printer. – laniakea Dec 02 '19 at 12:55
  • Did you try the last one? – Gerhard Dec 02 '19 at 13:00
  • Yes, I tried the third one as well, it tells me to check printer name – laniakea Dec 02 '19 at 13:01
  • Oh never mind, it seems printer has to be turned on in order for it to work. Thank you for code :) – laniakea Dec 02 '19 at 13:03
  • Okay, it failed on another printer name, it looks like this code depends on how many spaces are there in printer name. For example, it works fine when the printer name is 'Xerox Phaser 3052', but if printer name is 'HP LaserJet Professional P1102 on scorpiond' it fails. – laniakea Dec 03 '19 at 11:44
  • 1
    Works perfectly well in all possible scenarios, thank you so much. – laniakea Dec 05 '19 at 05:36