JSI Tip 8415. How can I set a user's default printer in a batch script?


In tip 0672, you set a users default printer using the registry.

In tip 2014, I introduced rundll32 printui.dll,PrintUIEntry /?

To use the RUNDLL32 PRINTUI.DLL,PrintUIEntry command to set a user's default printer, the syntax is:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "Printer Name"

where "Printer Name" can be a local printer or a remote printer.

Examples:

To set a local printer as the logged on user's default:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "HP OfficeJet R80xi"

To set a remote printer as the logged on user's default:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n"\\JSI001.JSIINC.COM\HP Business Inkjet 2250 (PCL5C)"

To retrieve the logged on user's default printer from the registry:

for /f "Tokens=2*" %%a in ('REG query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /V Device^|find "REG_SZ"') do (
 set device=%%b
)
where REG.EXE is either built-in (Windows XP and Windows Server 2003), or from the Windows 2000 Support Tools on the CD-ROM.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish