AddPrinter Utility
Charles Dye cdye@unm.edu
version 1.3.0 2021-08-31
Purpose:
AddPrinter is a command-line utility to install a printer on the local machine. It can be used in a logon script to automatically set up the printers appropriate for a specific user or workstation.
Syntax:
ADDPRINTER printername drivername /A:address /C:comment /D /I:filename /L:location /O /P:port /Q:queue /R:filename /T
| printername | the name to give the new printer |
| drivername | as listed in the printer’s installation .INF file |
/A:address | a dotted-quad IP address or hostname; a TCP/IP port will be created |
/C:comment | an optional comment, 255 characters max |
/D | make the new printer the default |
/I:filename | filename of the printer’s installation .INF file |
/L:location | the printer’s physical location, 255 characters max |
/O | only install if the printer named does not already exist |
/P:port | name of an existing printer port |
/Q:queue | the queue name for an LPR port |
/R:filename | read printer settings from a data file |
/T | send a test page after installing |
/XC:n | default color mode: 1 black and white, 2 color |
/XD:n | default duplex mode: 1 single-sided, 2 flip on long edge, 3 flip on short edge |
/XO:n | default orientation: 1 portrait, 2 landscape |
/XP:n | default paper size: 1 letter, 5 legal, 9 ISO A4 |
You must supply both the printername and
drivername parameters. /I:filename
might not be necessary if Windows includes support for the printer, or if
the driver is already installed on the local computer.
Specify either /A:address or
/P:port, but not both. /P
will use an existing printer port; /A will automatically
create a TCP/IP port for the specified address. The new IP port will be a
raw TCP port unless /Q:queue
is specified, in which case an LPR port will be created.
If you need to specify a TCP port number, append it to the IP address
with a colon, e.g. /A:192.168.10.24:9101.
If you specify /I:, AddPrinter will search for the tag
<Win> in the filename and,
if found, replace it with a string indicating the Windows version. This
allows you to supply more than one driver, and select the appropriate one
at runtime.
<Win> | |
| XP | Windows XP, Server 2003 |
| Vista | Windows Vista, Server 2008 |
| Win7 | Windows 7, Server 2008 R2 |
| Win8 | Windows 8 x86, Windows 8.1 x86, Server 2012 x86 |
| Win10 | Windows 10 x86, Server 2016 x86 |
| Winx.y | unknown version of Windows; major version x, minor version y |
For example, if you type /I:"Drivers\Yoyodyne 4200n\<Win>\oemsetup.inf",
the filename will be expanded at runtime to e.g.
“Drivers\Yoyodyne 4200n\XP\oemsetup.inf” or
“Drivers\Yoyodyne 4200n\Win7\oemsetup.inf”. (If a driver
supports more than one operating system, consider using NTFS junctions to
map one directory to another.)
If you need to distinguish between x86 and x64 environments, you can use
<x64>. This tag is removed in x86 environments, but
replaced with “-x64” in 64-bit environments. For example, if
you type /I:"Printers\DrizzleJet 6502<x64>\oemsetup.inf",
the filename will be either “Printers\DrizzleJet 6502\oemsetup.inf” or
“Printers\DrizzleJet 6502-x64\oemsetup.inf”, as appropriate.
Case is not significant in the <Win> and
<x64> tags. Remember to quote any parameter containing
spaces, less-than or greater-than signs, or any other special characters.
If you specify /R:, AddPrinter will attempt to load printer
settings from the specified data file. You can use the batch file
SaveSettings.cmd to save the settings from the exact same printer to a
file. Doing this allows you to configure default options like paper trays,
duplexing, secured or locked printing, and so forth on one computer; then
replicate the printer with its customizations to other systems. The
filename supports the same tags as in /I:.
The preference options /XC:, /XD:, /XO:,
and /XP: set printing preferences for the current user —
the user performing the install. Other users who access the printer will use the
driver’s built-in defaults.
• Note: Installing printer drivers under Vista or later may require elevation (“Run as Administrator”.)
Example:
addprinter "Laser in Office" "FooTronic 690 PCL6" /a:192.168.0.16 /i:"C:\Drivers\FooTronic 690\oemsetup.inf"
Disabling AddPrinter:
To prevent AddPrinter from installing printers on a specific computer, create a registry value:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\University of New Mexico\College of Education\AddPrinter]
"Disable"=dword:00000001
Exit Codes:
| 0 | Printer successfully created |
| 0 | /O specified and printer already exists; did nothing |
| 0 | Syntax request via /? |
| 1 | Any syntax error |
| 2 | Any error while adding printer; printer was not created |
| 2 | Disabled by registry entry |
Download:
You can download the current version here. You can also get the source code.
Changes:
| 1.3.0 | 2021-08-31 | When creating a TCP/IP printer port, always generates a new, unique port name. The <Win> tag now recognizes Windows 8 and Windows 10. The <Win> tag no longer appends “-x64” for 64-bit Windows; use <x64> if you need to make the distinction. Tweaks to the version info structure. Using only UPX to compress the binary; no more MPRess. Sundry cleanup of the code. |
| 1.2.0 | 2016-08-17 | Adds /XC: /XD: /XO: /XP: to set printing preferences. |
| 1.1.1 | 2015-01-15 | No functional change; compressed the binary with UPX instead of MPRESS to avoid a false positive from a certain unnamed antivirus product which is, inexplicably, much used at UNM. |
| 1.1.0 | 2012-03-01 | previous release |
Acknowledgments:
The snazzy printer icon is from the Oxygen theme for KDE: http://www.oxygen-icons.org/
I compress the binaries using UPX (http://upx.sourceforge.net/).
Status and Licensing:
This program is copyright © 2021, The University of New Mexico College of Education & Human Sciences. Unaltered copies of the binaries and documentation may be freely distributed without restriction. No warranty is made for correct operation or suitability for any purpose; use it at your own risk.