Another way to set a user's default printer in a batch script.

In tip 8415 ยป How can I set a user's default printer in a batch script and links, we used various methods to set a user's default printer.

I have scripted SetDefPrt.bat to set a user's default printer, and connect it if necessary.

The syntax for using SetDefPrt.bat is:

\[call\] SetDefPrt Printer

Where Printer is either \\ServerName\ShareName, like \\JSI001\HP2250, or \\ServerName\PrinterName, like "\\JSI001.JSIINC.COM\HP Business Inkjet 2250 (PCL5C)".

SetDefPrt.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: SetDefPrt Printer&goto :EOF
if exist "%TEMP%\SetDefPrt.vbs" goto doit
@echo.Dim oNwk, sPrt, oArg>"%TEMP%\SetDefPrt.vbs"
@echo.set oArg = Wscript.Arguments>>"%TEMP%\SetDefPrt.vbs"
@echo.sPrt = oArg(0)>>"%TEMP%\SetDefPrt.vbs"
@echo.Set oNwk = CreateObject("WScript.Network")>>"%TEMP%\SetDefPrt.vbs" 
@echo.oNwk.AddWindowsPrinterConnection sPrt>>"%TEMP%\SetDefPrt.vbs"
@echo.oNwk.SetDefaultPrinter sPrt>>"%TEMP%\SetDefPrt.vbs"
@echo.WScript.Quit>>"%TEMP%\SetDefPrt.vbs"
:doit
cscript //nologo "%TEMP%\SetDefPrt.vbs" %1


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