Installing printer with a single script.

I’ll keep it short this time.

Task: Deploy network printer drivers along with the install script to a number of machines.
New local TCP/IP port is required for the printer (if exists – delete and re-create), then copy drivers and install printer.

The batch script bellow will use the set of “Printing Admin Scripts” that you can find on each Windows 7 Pro/Ent/Ultimate as well as Windows 8.1 and Windows 10 under C:\Windows\System32

Now, our printer IP is: 192.168.1.100
Printer name is: Xerox WorkCentre 7435
Location: Office

Remember the varDriver has to be the actual driver name (ie.¬†TOSHIBA Universal Printer 2 or Xerox WorkCentre 7435 as in this particular example). If it won’t match the driver name from the .inf file, you’ll get “error 87 – unable to add printer” and the script won’t work.

you can set varDriverFolder and varDriverFile as network share as well as local hard drive location.

CLS
@ECHO off

SET varIP=192.168.1.100
SET varDriver=Xerox WorkCentre 7435
SET varDriverFolder=C:\Setupfiles\XeroxWorkCentre7435
SET varDriverFile=C:\Setupfiles\XeroxWorkCentre7435\x2GOAKL.inf
SET varName=Xerox WorkCentre 7435
SET varLocation=Office

REM "Deleting TCP/IP port"
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r IP_%varIP%

REM "Creating TCP/IP port"
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_%varIP% -o raw -n 9100 -h %varIP%

CLS
REM "Installation message"
@ECHO.
@ECHO The %varLocation% printer is currently being installed.
@ECHO.
@ECHO Please do not close this window.
@ECHO.
@ECHO Once the installation is complete this Setup window will exit.
@ECHO.

REM "Driver installation"
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "%varDriver%" -h "%varDriverFolder%" -i "%varDriverFile%"  
CLS

REM "Printer deletion"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "%varName%" 
CLS

REM "Printer installation"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a -p "%varName%" -m "%varDriver%" -r "IP_%varIP%"
CLS

REM "Location configuration"
@ECHO.
@ECHO Completing installation.
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
CLS

REM "Making it Default printer"
CSCRIPT %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -p "%varName%" -t

For Altiris users:

Create detection rule as “Registry Key Value” and point it to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\Xerox WorkCentre 7435 with the registry entryPortand registry valueIP_192.168.1.100”¬†

You can also use the script below to add server shared printer and set it as default (it won’t set it for all users though)

[code]CLS
@Echp off
SET serverhostname=SERVER
SET sharedprinterName=PRINTER
REM Adding printer
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -ac -p “\\%serverhostname%\%sharedprinterName%”
REM Stopping the Print Spooler Service
net stop spooler
REM Starting the Print Spooler Service
net start spooler
REM Making it Default printer
CSCRIPT /nologo %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p “\\%serverhostname%\%sharedprinterName%”[/code]