Batch – Add TCP/IP Printer via Scripted Commands

email me

{updated on 5/21/2019}

Network Method

Install specific printer based upon part of the computer name

set PCName=%computername%

echo %PCName% | findstr /C:”LAB1″ >nul

if errorlevel 1 (
cscript c:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_10.10.10.101 -h 10.10.10.101
rundll32 printui.dll,PrintUIEntry /ga /if /b “Lab 2” /f C:\printer_driver\hpcu150t.inf /r “IP_10.10.10.101” /m “HP Universal Printing PCL 5” /Z
) ELSE (
cscript c:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_10.10.10.102 -h 10.10.10.102
rundll32 printui.dll,PrintUIEntry /ga /if /b “Lab 1” /f C:\printer_driver\hpcu150t.inf /r “IP_10.10.10.102” /m “HP Universal Printing PCL 5” /Z
)

 
Just Install Printer via TCP/IP Address

cscript c:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_10.10.10.100 -h 10.10.10.100

rundll32 printui.dll,PrintUIEntry /ga /if /b “Printer 1” /f C:\printer_driver\hpcu150t.inf /r “IP_10.10.10.100” /m “HP Universal Printing PCL 5” /Z

 

 

:: Enable Legacy Mode – Disables Windows 10 Printer Management
reg add “HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows” /v LegacyDefaultPrinterMode /t REG_DWORD /d 1 /f /reg:64

:: Create the TCP/IP printer port on the computer with IP address
cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnport.vbs -a -r IP_10.10.10.10 -h 10.10.10.10 

:: Install the HP Universal PCL 6 print driver
:: Requires driver to be available on a network share
:: The /m “printer name” must match what’s available in the INF file
rundll32 printui.dll,PrintUIEntry /ia /m “HP Universal Printing PCL 6” /f “\\ServerName\printers\HPUPD\PCL\hpcu118c.inf”

:: Create the printer on the computer
rundll32 printui.dll,PrintUIEntry /ga /if /q /b “ABC_Printer” /f “\\ServerName\printers\HPUPD\PCL\hpcu118c.inf” /r “IP_10.10.10.10” /m “HP Universal Printing PCL 6”

 

Local Method

:: Enable Legacy Mode – Disables Windows 10 Printer Management
reg add “HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows” /v LegacyDefaultPrinterMode /t REG_DWORD /d 1 /f /reg:64

:: Create port
cscript c:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_10.10.10.10 -h 10.10.10.10

:: Install printer using INF
:: The printer driver must already be installed, or locally available
:: the /m “printer name” must match what’s available in the INF file
rundll32 printui.dll,PrintUIEntry /ga /if /b “ABC_Printer” /f C:\Windows\inf\oem8.inf /r “IP_10.10.10.10” /m “HP Universal Printing PCL 5” /Z

:: OR

:: Install from local printer driver source files
rundll32 printui.dll,PrintUIEntry  /ga /if /b “PC Lab 4” /f C:\printer_driver\hpcu150t.inf /r “IP_10.10.10.10” /m “HP Universal Printing PCL 5” /Z

:: Set printer as default
:: Must run in Current User security context
timeout /t 60
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n “ABC_Printer”

 

Notes

/q = hide messages

Launch Add Printer Wizard
printui.dll,PrintUIEntryDPIAware /im

 

 

PrintBRM.exe

%windir%\System32\Spool\Tools\PrintBRM.exe -?

Access the Backup Recovery Migration tool through a command line interface.

PrintBrm -B|R|Q [-S <server>] -F <file> [-D <directory>] [-O FORCE] [-P ALL|ORIG] [-NOBIN] [-LPR2TCP] [-C <config file>] [-NOACL] [-?]
-B Backup the server to the specified file
-R Restore the configuration in the file to the server
-Q Query the server or the backup file
-S <server name> Target server
-F <file name> Target backup File
-D <directory> Unpack the backup file to (with -R) or repack a backup file from (with -B) the given directory
-O FORCE Force overwriting of existing objects
-P ALL|ORIG Publish all printers in directory, or publish printers that were published originally
-NOBIN Omit the binaries from the backup
-LPR2TCP Convert LPR ports to Standard TCP/IP ports on restore
-C <file name> Use the specified configuration file for BRM
-NOACL Remove ACLs from print queues on restore
-? Display this help

Examples

Export
%windir%\System32\Spool\Tools\PrintBRM.exe -s \\source -b -f file.printerExport

Import
%windir%\System32\Spool\Tools\PrintBRM.exe -s \\target -r -f file.printerExport

 

Prncnfg.vbs

Prncnfg.vbs Printer configuration
Prndrvr.vbs Printer driver configuration
Prnjobs.vbs Print job monitoring
Prnmngr.vbs Printer management
Prnport.vbs Printer port management
Prnqctl.vbs Printer queue management
Pubprn.vbs Publish a printer to Active Directory

 

Prncnfg.vbs

The Prncnfg.vbs script provides you with a printer configuration utility that allows you to display and change printer configuration information. It will also allow you to rename a printer.

This printer configuration utility can come in handy in a number of different situations. For instance, suppose you want to build an inventory database of all the printers on your network. You can take advantage of the Prncnfg.vbs script’s ability to display printer configuration information. To do so, you use this command syntax:

cscript prncnfg.vbs -g [-s ServerName] -p PrinterName [-u UserName -w Password]

You could then use the redirection symbols on the actual command line to compile the output into a text file that you could later import into a database or a spreadsheet. The parameters used in this command are defined in Table B.

Table B: Parameters to configure the Prncnfg.vbs script to display printer configuration information.

Parameter

Description

-g Required. Specifies that you want to display configuration information about a printer.
-s ServerName Optional. Specifies the name of the remote computer sharing the printer. If you do not specify a computer name, the local computer is used.
-p PrinterName Required. Specifies the name of the printer about which you want to display information.
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.

Prndrvr.vbs

The Prndrvr.vbs script provides you with a printer driver utility that allows you to list and examine printer drivers. This utility will also allow you to delete and add printer drivers.

If you’re troubleshooting a printer problem that could possibly be linked to outdated or missing printer drivers, you can use the Prndrvr.vbs script to quickly build a list of all the files that make up the printer driver, which you could then use for comparison. To do so, you use this command syntax:

cscript prndrvr.vbs -l [-s ServerName] [-u UserName -w Password]

The parameters used on this command line are defined in Table C.

Table C: Parameters to configure the Prndrvr.vbs script to list all the printer driver files.

Parameter

Description

-l Required. Specifies that you want to list all the drivers on a computer.
-s ServerName Optional. Specifies the name of the remote computer sharing the printer. If you do not specify a computer, the local computer is used.
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.

Prnjobs.vbs

The Prnjobs.vbs script provides you with a print job monitoring utility that allows you to pause, resume, cancel, and list print jobs. Suppose that there are a number of network printers to which you can print and you have an urgent print job. You can use the Prnjobs.vbs script to browse around for the least busy printer. To do so, you’d use this command syntax:

cscript prnjobs -l [-s ServerName] [-p PrinterName] [-u UserName -w Password] 

The parameters used on this command line are defined in Table D.

Table D: Parameters to configure the Prnjobs.vbs script to list all the print queue.

Parameter

Description

-l Required. Specifies that you want to list all the print jobs in a print queue.
-s ServerName Optional. Specifies the name of the remote computer sharing the printer. If you do not specify a computer, the local computer is used.
-p PrinterName Optional. Specifies the name of the printer whose print queue contains the jobs you want to list. If you do not specify a printer, then all jobs in all print queues are listed.
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display print job information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.

Prnmngr.vbs

The Prnmngr.vbs script provides you with a printer management utility that allows you to add, delete, and list printer connections. It will also allow you to set and display the default printer.

The Prnmngr.vbs script can come in handy if you need to quickly add a new network printer connection to a group of computers. You could create a script or a batch file that automates the installation procedure via the Prnmngr.vbs script. To do so, you’d use the command syntax:

cscript prnmngr.vbs -a -p PrinterName [-s ServerName] -m DriverName -r PortName [-u UserName -w Password]

The parameters used on this command line are defined in Table E.

Table E: Parameters to configure the Prnmngr.vbs script to add a new printer.

Parameter Description
-a Required. Specifies that you want add a printer.
-p PrinterName Required. Specifies the name of the printer that you want to add.
-s ServerName Optional. Specifies the name of the remote computer to which you want to add a printer. If you do not specify a computer, the printer is added to the local computer.
-m DriverName Required. Specifies the name of the driver for the local printer you want to add.
-r PortName Required. Specifies the port to which the printer is connected. If this is a parallel or a serial port, use the ID of the port (for example, LPT1 or COM1). If this is a TCP/IP port, use the port name that was specified when the port was added
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer to which you want to add a local printer. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.

Prnport.vbs

The Prnport.vbs script provides you with a printer port management utility that allows you to create, delete, and list standard TCP/IP printer ports. It also allows you to display and change port configuration.

Suppose that you need to create a standard TCP/IP printer port. If you already have all the settings in hand, you can perform the operation very quickly using the Prnport.vbs script with this syntax

cscript prnport.vbs -a -r PortName [-s ServerName] -h HostAddress [-u UserName -w Password] [-o {raw -n PortNumber | lpr}] [-q QueueName] [-m{e | d}] [-i SNMPName] [-y CommunityName] [-2{e | d}]

The parameters used on this command line are defined in Table F.

Table F: Parameters to use the Prnport.vbs script to create a standard TCP/IP printer port.

Parameter

Description

-a Required. Specifies that you want to create a standard TCP/IP port.
-r PortName Required. Specifies the port to which the printer is connected.
-s ServerName Optional. Specifies the name of the remote computer to which you want to add the port. If you do not specify a computer, the port is added to the local computer.
-h HostAddress Required. Specifies the IP address you want to assign to the port.
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer on which you want to create a standard TCP/IP printer port. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
-o {raw -n PortNumber | lpr} Optional. Specifies which protocol the port uses: TCP raw or TCP LPR.
-q QueueName Optional. Specifies the queue name for a TCP raw port.
-m{e | d} Optional. Specifies whether SNMP is enabled. The parameter e enables SNMP. The parameter d disables SNMP.
-i SNMPName Optional. Specifies the SNMP index, if SNMP is enabled.
-y CommunityName Optional. Specifies the SNMP community name, if SNMP is enabled.
-2{e | d} Optional. Specifies whether double spools (also known as respooling) are enabled for TCP LPR ports.

Prnqctl.vbs

The Prnqctl.vbs script provides you with a printer queue management utility that allows you to pause or resume a printer as well as to clear a printer queue. It also allows you to print a test page on a printer.

When troubleshooting printer problems, chances are that you find yourself often printing test pages, which can be a multistep operation. The neatest feature of the Prnqctl.vbs script is that it allows you to quickly print a test page right from the command line. As such, if you were to create a simple script that automates the Prnqctl.vbs script, you could print a test page just by double-clicking an icon. To do so, you’d use the syntax:

cscript prnqctl.vbs -e [-s ServerName] -p PrinterName [-u UserName -w Password]

The parameters used on this command line are defined in Table G.

Table G: Parameters to use the Prnqctl.vbs script to print a test page.

Parameter

Description

-e Required. Specifies that you want to print a test page.
-s ServerName Optional. Specifies the name of the remote computer sharing the printer on which you want to print a test page. If you do not specify a computer, the local computer is used.
-p PrinterName Required. Specifies the name of the printer on which you want to print a test page.
-u UserName -w Password Optional. Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer on which you want to print a test page. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.

Pubprn.vbs

The Pubprn.vbs script provides you with a tool that you can use to easily publish a printer to your Active Directory. To do so, you’d use the syntax:

cscript pubprn.vbs ServerName LDAP://CN=<Container>,DC=<Container>"

The parameters used on this command line are defined in Table H.

Table H: Parameters to publish a printer to Active Directory.

Parameter

Description

ServerName Optional. Specifies the name of the Windows server that hosts the printer that you want to publish. If you do not specify a computer, the local computer is used.
“LDAP://CN=<Container>, DC=<Container>” Specifies the path to the container in Active Directory Domain Services where you want to publish the printer.

 

 

printui.dll

Usage: rundll32 printui.dll,PrintUIEntry [options] [@commandfile]

/a[file] binary file name
/b[name] base printer name
/c[name] unc machine name if the action is on a remote machine
/dl delete local printer
/dn delete network printer connection
/dd delete printer driver
/e display printing preferences
/f[file] either inf file or output file
/F[file] location of an INF file that the INF file specified with /f may depend on
/ga add per machine printer connections (the connection will be propagated to the user upon logon)
/ge enum per machine printer connections
/gd delete per machine printer connections (the connection will be deleted upon user logon)
/h[arch] driver architecture one of the following, x86, x64 or Itanium
/ia install printer driver using inf file
/id install printer driver using add printer driver wizard
/if install printer using inf file
/ii install printer using add printer wizard with an inf file
/il install printer using add printer wizard
/im install printer using add printer wizard skiping network listed printers
/in add network printer connection
/ip install printer using network printer installation wizard
/j[provider] print provider name
/k print test page to specified printer, cannot be combined with command when installing a printer
/l[path] printer driver source path
/m[model] printer driver model name
/n[name] printer name
/o display printer queue view
/p display printer properties
/q quiet mode, do not display error messages
/r[port] port name
/s display server properties
/Ss Store printer settings into a file
/Sr Restore printer settings from a file
Store or restore printer settings option flags that must be placed at the end of command:
2 PRINTER_INFO_2
7 PRINTER_INFO_7
c Color Profile
d PrinterData
s Security descriptor
g Global DevMode
m Minimal settings
u User DevMode
r Resolve name conflicts
f Force name
p Resolve port
i Driver name conflict
/u use the existing printer driver if it’s already installed
/t[#] zero based index page to start on
/v[version] driver version one of the following, “Type 2 – Kernel Mode” or “Type 3 – User Mode”
/w prompt the user for a driver if specified driver is not found in the inf
/y set printer as the default
/Xg get printer settings
/Xs set printer settings
/z do not auto share this printer
/Y do not auto generate a printer name
/K changes the meaning of /h to accept 2, 3, 4 for x86, x64, or Itanium (respectively), and /v to accept 3 for “Type 3 – User Mode”
/Z share this printer, can only be used with the /if option
/? help this message
@[file] command line argument file
/Mw[message] show a warning message before committing the command
/Mq[message] show a confirmation message before committing the command
/W[flags] specifies flags and switches for the wizards (for APW & APDW)
r make the wizards to be restart-able from the last page
/G[flags] specifies global flags and switches
w suppress setup driver warnings UI (super quiet mode)
/R force selected driver to replace exisiting driver


Examples

Run server properties:
rundll32 printui.dll,PrintUIEntry /s /t1 /c\\machine

Run printer properties:
rundll32 printui.dll,PrintUIEntry /p /n\\machine\printer

Run add printer wizard locally:
rundll32 printui.dll,PrintUIEntry /il

Run add printer wizard on \\machine:
rundll32 printui.dll,PrintUIEntry /im /c\\machine

Run queue view:
rundll32 printui.dll,PrintUIEntry /o /n\\machine\printer

Run inf install:
rundll32 printui.dll,PrintUIEntry /if /b “Test Printer” /f c:\infpath\infFile.inf /r “lpt1:” /m “Brother DCP-128C”

Run inf install (with inf dependency). In the example, prnbr002.inf depends on ntprint.inf
rundll32 printui.dll, PrintUIEntry /ia /m “Brother DCP-128C” /K /h x64 /v 3 /f “c:\infpath\prnbr002.inf” /F “c:\infpath\ntprint.inf”

Run add printer wizard using inf:
rundll32 printui.dll,PrintUIEntry /ii /f c:\infpath\infFile.inf

Add printer using inbox printer driver:
rundll32 printui.dll,PrintUIEntry /if /b “Test Printer” /r “lpt1:” /m “Brother DCP-128C”

Add per machine printer connection (propagated to the user upon logon):
rundll32 printui.dll,PrintUIEntry /ga /c\\machine /n\\machine\printer /j”LanMan Print Services”

Delete per machine printer connection (the connection will be deleted upon user logon):
rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer

Enumerate per machine printer connections:
rundll32 printui.dll,PrintUIEntry /ge /c\\machine

Add printer driver using inf:
rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m “Brother DCP-128C” /h “x86” /v “Type 3 – User Mode” /f c:\infpath\infFile.inf

Add printer driver using inf:
rundll32 printui.dll,PrintUIEntry /ia /K /c\\machine /m “Brother DCP-128C” /h “x86” /v 3

Add inbox printer driver:
rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m “Brother DCP-128C” /h “Intel” /v “Type 3 – Kernel Mode”

Remove printer driver:
rundll32 printui.dll,PrintUIEntry /dd /c\\machine /m “Brother DCP-128C” /h “x86” /v “Type 3 – User Mode”

Remove printer driver:
rundll32 printui.dll,PrintUIEntry /dd /K /c\\machine /m “Brother DCP-128C” /h “x86” /v 3

Set printer as default:
rundll32 printui.dll,PrintUIEntry /y /n “printer”

Set printer comment:
rundll32 printui.dll,PrintUIEntry /Xs /n “printer” comment “My Cool Printer”

Get printer settings:
rundll32 printui.dll,PrintUIEntry /Xg /n “printer”

Get printer settings saving results in a file:
rundll32 printui.dll,PrintUIEntry /f “results.txt” /Xg /n “printer”

Set printer settings command usage:
rundll32 printui.dll,PrintUIEntry /Xs /n “printer” ?

Store all printer settings into a file:
rundll32 printui.dll,PrintUIEntry /Ss /n “printer” /a “file.dat”

Restore all printer settings from a file:
rundll32 printui.dll,PrintUIEntry /Sr /n “printer” /a “file.dat”

Store printer information on level 2 into a file:
rundll32 printui.dll,PrintUIEntry /Ss /n “printer” /a “file.dat” 2

Restore from a file printer security descriptor:
rundll32 printui.dll,PrintUIEntry /Sr /n “printer” /a “file.dat” s

Restore from a file printer global devmode and printer data:
rundll32 printui.dll,PrintUIEntry /Sr /n “printer” /a “file.dat” g d

Restore from a file minimum settings and resolve port name:
rundll32 printui.dll,PrintUIEntry /Sr /n “printer” /a “file.dat” m p

Enable Client Side Rendering for a printer:
rundll32 printui.dll,PrintUIEntry /Xs /n “printer” ClientSideRender enabled

Disable Client Side Rendering for a printer:
rundll32 printui.dll,PrintUIEntry /Xs /n “printer” ClientSideRender disabled

 

tags: MrNetTek