Today we’ll talk about opportunities of installing printers and their drivers from the command line in Windows 8 and Windows Server 2012 / R2. It can be useful in various scenarios unattended printer installation in SCCM tasks, logon scripts of the group policies and on the servers running in the Server Core mode.
Ready-to-Use VBS Scripts to Manage Printers in Windows
To manage printers, Microsoft has developed several VBS scripts that allow to manage printers and print queues, install and uninstall printer drivers, etc.
These scripts are present in all Windows versions (starting from Vista and Windows Server 2008) and are stored in the directory C:\Windows\System32\Printing_Admin_Scripts\en-US
The following VBS scripts are located in this folder:
- Prncnfg.vbs – a script to display printer settings
- Prndrvr.vbs – managing printer drivers (driver installation/removal)
- Prnjobs.vbs – managing print jobs
- Prnmngr.vbs – managing printers (including creating and removing printer in the system)
- Prnport.vbs – managing connection to the remote printer via TCP/IP port
- Prnqctl.vbs – control over print jobs running
- Pubprn.vbs – managing printer publishing in Active Directory
Let’s consider typical scenarios of using these VBS scripts.
How to Install a Printer Driver from the Command Line
Suppose we have to install the HP Universal Printer Driver on a PC of a user. Download the corresponding driver version from the manufacturer’s website and unpack it to any directory (e.g., C:\drivers\HP Universal Print Driver)
Install the printer driver with the command:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -a -m "HP Universal Printing PCL 6" -i "C:\ drivers \HP Universal Print Driver\hpcu160u.inf"
Let’s consider the parameters of the command:
-а – adds printer driver
-m “HP Universal Printing PCL 6″– the name of the printer driver
-i “path” – the full path to the INF file of the driver
After the driver is installed, it appears in the print server properties (Control Panel\Hardware and Sound\Devices and Printers ->Print Server Properties).
How to Add a New Printer to the System from the Command Line
With the following command, we will create a new printer with the name HP5520 using the previously installed driver.
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "HP5520" -m "HP Universal Printing PCL 6" -r "lpt1:"
-a – a new local printer is installed
-p “HP5520″ – a display name of the printer
-m “HP Universal Printing PCL 6″ – a print driver that is used
-r “lpt1:” – a name of the port used
How to Create a TCP/IP Port for a Network Printer
If the printer to be installed is a network printer, you have to create a network port for it first. To do it, create a network port (suppose the printer IP address is 192.168.10.26):
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\Prnport.vbs" -a -r IP_192.168.1.22 -h 192.168.1.22 -o raw -n 9100
-r IP_192.168.1.22 – a name of the network port
-h 192.168.1.22 – IP address of the device
-o raw – a port type (raw or lpr)
-n 9100 – the number of the TCP port of the device (usually 9100)
Then install a new network printer in the system:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "HP5525" -m "HP Universal Printing PCL 6" -r " IP_192.168.1.22"
After the script is over, a new printer HP5525 appears in the system
How to Print a Test Page
To print a test page on the printer you have created, do the following:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnqctl.vbs” -e -p "HP5525"
How to Remove a Printer and Its Driver
A printer can be removed with the following command:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -d -p "HP5525"A driver is removed as follows:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -d -m "HP Universal Printing PCL 6" -e "Windows x64" -v 3
In this article we considered the basic operations with good old Microsoft VBS scripts that allow to manage printers and their drivers from the command line in different Windows versions. The full list of opportunities and arguments of these scripts are available in Microsoft documentation or in the in-built help of the scenarios (just run the script file without parameters in the command line).
In the next article we will deal with new opportunities of printer management in Windows 8 / Server 2012 provided by Powershell.