Install network printers from the command line in Windows

Here’s a script to install network printers from the command line in Windows. It works on XP, Vista and 7 and I think it will in Windows 8.

You’ll need the location to the exact driver the client needs. This could be a mapped share. I used a usb key and since all machines I ran it on were identical I knew the exact volume name beforehand. If you don’t, you could get it by capturing the output of the CD command, like this:


for /f %i in ('cd') do set vol=%~di

The current volume name is then stored in the %vol% variable.

Since I needed to add three printers each time I wrote a little for-loop that called the routine to install the printer.

The location is freestyle but the convention is to ‘zoom in’ on the printer so it’s easy to find it from a list, like so: Country/Locality/Street or office/floor number/printer number. Anything will work but if you stick to (a variation on) this example your users will always be able to quickly find a nearby printer.

Here’s a TechNet Library article that explains more about Prnport.vbs.



@echo off

:: Install printer
cd /d c:\windows\system32

:: Usage:
:: Call :AddPrinter [ip address] [path to .inf driver] [driver name] [printer name] [printer location]
:: Example:
:: Call :AddPrinter 10.0.0.7 "E:\Drivers\Oce\KOAZ8JA_.inf" "Generic 36C-1SeriesPCL" "Oce copier" "NL/Rotterdam/Weena/Floor 5"

goto :eof

:AddPrinter
set ip=%1
set inf=%2
set drivername=%3
set printername=%4
set location=%5

echo Installing printer %printername%...
echo.

::Errorhandling
if [%5]==[] goto :NotEnoughParams

::Create port
cscript prnport.vbs //NoLogo //B -a -r IP_%ip% -h %ip% -o raw

::Add driver
cscript prndrvr.vbs //NoLogo //B -a -i %inf% -m %drivername%

::Install printer
cscript prnmngr.vbs //NoLogo //B -a -p %printername% -r IP_%ip% -m %drivername%

::Configure printer
cscript prncnfg.vbs //NoLogo //B -t -p %printername% -l %location%

goto :eof

:NotEnoughParams
echo Missing parameter(s)
goto :eof

Back to Top