Computer >> Computer tutorials >  >> System >> Windows Server

Managing Printers from the Command Prompt in Windows 10 / 8.1

Today we’ll talk about opportunities of managing printers and their drivers from the command prompt in Windows 10/ 8.1 and Windows Server 2012 R2/ 2016. We will consider how to install a new local or network printer, print driver, create a TCP/IP print port, print a test page, delete a driver or printer using simple Windows commands. 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 you 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 located in the directory C:\Windows\System32\Printing_Admin_Scripts\en-US.

  Note.

  1. Instead of en-US directory, there can be another directory corresponding to the system language;
  2. In Windows XP and 2003 these VBS scenarios are stored in the C:\WINDOWS\system32 directory.

Managing Printers from the Command Prompt in Windows 10 / 8.1

The following VBS scripts are located in this folder:

  • Prncnfg.vbs – a script to display information about the printer settings;
  • Prndrvr.vbs – printer driver management (install / uninstall printer drivers);
  • 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 ports;
  • Prnqctl.vbs – print queue management;
  • Pubprn.vbs – managing printer publishing in Active Directory.
Note. One of the well-known ways of managing printers in different versions of Windows is the host process rundll32.exe, which receives the name of the library printui.dll and the entry point to it (PrintUIEntry). The command rundll32 printui.dll,PrintUIEntry is enough to perform basic operations with printers and is fully supported by Microsoft, but the use of specified vbs scripts is preferable from the administrator point of view.

Let’s consider typical scenarios of using these VBS scripts.

How to Install a Printer Driver from the Command Line?

Permissions to install and configure local printers are available for members of the following local groups: Administrators, Print Operators or Server groups.

Install the HP printer driver using the command:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -a -m "HP Universal Printing PCL 6" -i "C:\drv\HP Universal Print Driver\hpcu160u.inf"

Managing Printers from the Command Prompt in Windows 10 / 8.1Let’s consider the parameters of the command:

-a – add printer driver;

-m “HP Universal Printing PCL 6”– the name of the printer driver;

-i “path” – the full path to the driver’s INF file.

After the driver is installed, it appears in the print server properties (Control Panel\Hardware and Sound\Devices and Printers -> Print Server Properties).

Managing Printers from the Command Prompt in Windows 10 / 8.1

Note. If you are using an incompatible printer driver, you can install it manually.

How to Add a New Printer from the Command Prompt?

Using the following command, you can install a new printer named HP5525 using the previously installed HP Universal Printing PCL 6 print driver:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "HP5520" -m "HP Universal Printing PCL 6" -r "lpt1:"

Managing Printers from the Command Prompt in Windows 10 / 8.1

-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 local print port used. In this case, printing should be performed through the LPT port. Here you can specify the parallel port (LPT1:, LPT2:), serial (COM1:, COM2: – before installation, make sure that this COM port is not used by another device) or USB port (USB001, etc.).

Managing Default Printer Using CMD

From the command line, you can choose which printer to use for default printing. With the following command you can list all installed printers:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" –l

You can get the name of the current default printer:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" –g

Managing Printers from the Command Prompt in Windows 10 / 8.1

The default printer is HP Universal Printing PCL 6 (redirected 1)

To set a different default printer, run the command:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -t –p "HP5525"

How to Create a TCP/IP Port for a Network Printer?

If you want to connect a network printer, you must first create a TCP/IP printer port for it (suppose the printer IP address is 192.168.1.22):
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).

And then you can install a new network printer on 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.

Managing Printers from the Command Prompt in Windows 10 / 8.1

How to Print a Test Page from the CMD?

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"

Manage Print Queues from the Command Prompt

Using the prnjobs.vbs script, you can view print jobs in queues. To display all print jobs for all local printers, run the command:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnjobs.vbs” –l

To display jobs on a specific printer, you need to specify its name:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnjobs.vbs” –l –p HP5525

To clear the print queue on one printer, run the following command:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnjobs.vbs” –x –p HP5525

Or you can quickly clear all queues for all printers (this is much more convenient than manually cleaning the print queues):

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnjobs.vbs” –x

Share a Network Printer Using the Command Line

All new printers that you installed in Windows from the command prompt are local. You can share them with other users over the network from the Windows GUI (see the article). You can also share the printer from the command line. For example, you want to provide network access to your HP5525 printer by publishing it under the name HP5525_Shared. Use the command:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs” -t  -p  HP5525 -h "HP5525_Shared" +shared

To disable printer sharing, run:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs” -t -p "HP5525" -shared

Similarly, you can publish a printer in Active Directory:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs” -t  -p HP5525 +published

To remove printer from the AD, use the “-published” argument.

How to Add a Network Printer via the Command Line?

To connect a shared network printer connected to another computer, use the
command:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -ac -p “\\rome-prnt01\hp2100”

Quite frequent errors when connecting network printers – 0x00000002, 0x00000057 and 0x0000007e. Ways to solve errors are available at the links above.

How to Remove a Printer and Its Driver from the Command Prompt?

A complete list of printers in the system can be displayed as:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -l

A printer can be removed with the following command:
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -d -p "HP5525"
The print driver is deleted 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 looked the basic operations with good old Microsoft VBS scripts that allow to manage printers and their drivers from the command line in various Windows versions. A complete list of the capabilities 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 introduce a new opportunities of printer management in Windows 10 / 8.1 and Windows Server 2016 / 2012 R2 provided by PowerShell.