Today we’ll talk about opportunities for 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
- How to Install a Printer Driver from the Command Line?
- How to Add a New Printer from the Command Prompt?
- Managing Default Printer Using CMD
- How to Create a TCP/IP Port for a Network Printer?
- How to Print a Test Page from the CMD?
- Manage Print Queues from the Command Prompt
- Share a Network Printer Using the Command Line
- How to Add a Network Printer via the Command Line?
- How to Remove a Printer and Its Driver from the Command Prompt?
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.
- Instead of en-US directory, there can be another directory corresponding to the system language;
- In Windows XP and 2003 these VBS scenarios are stored in the C:\WINDOWS\system32 directory.
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.
Let’s consider typical scenarios of using these VBS scripts.
How to Install a Printer Driver from the Command Line?
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"
Let’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).
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:"
-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
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.
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”
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.
18 comments
This is GREAT info – I assume that windows 10 is the same?
I do have a question though – do you know of a way to attach to a shared printer on a server like \\server\printer1? I’ve tried to add the share name at the end of the port “part” but get several errors
You can try to add shared network printer using this command:
cscript prnmngr.vbs -ac -p “\\server\printer1”
Is it possible to add a user code in the printer configuration using command line ?
I didn’t understand your task…
To change the printer IP port you can use the command:
Prncnfg.vbs -t -p PRINTENAME -r PORTNAME
How can I select, inside my program, a specific printer, by name, and direct windows to use that specific printer to print my report, without using ou changing the default printer?
How to run wizard Printer automatic with Ip via cmd?
==> I want connect printer Ricoh C2004ex in Windows 10 Build 1903
Connect via cmd : rundll32 printui.dll,PrintUIEntry /in /n\\Ip-Printer\\mpc2004ex , it show no found driver, i try install driver but show error cannot install driver ‘RICOH MP C2004ex PCL 6’. I try run Wizard Printer, type ip printer Ricoh , install driver ‘RICOH MP C2004ex PCL 6’ show success.
‘script’ is not recognized as an internal or external command,
operable program or batch file. while running
script “C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs” -t -p “PRINTERNAME” -h “PrinterAlias” +shared
There is a typo in the article; replace the
script
command withcscript
is there a way to fill the location field ?
with powershell : set-printer -name “xxx” -location “xxx”
hi
i have problem when i try to use command
“cscript “C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs” -a -m “MesanalysesApp” -i “C:\gs\lib\ghostpdf.inf”
I had this problem
Unable to add printer driver MesanalysesApp Win32 error code 87
Is it possible, add printer with config file with .cfm?
Printer adds fine and visible by apps but doesnt show up in “printer and scanners” list in settings. WIN10 Home.
Fixed! Restarted the print services.
If anyone has issue with the IP address there is an extra space added in the example – remove it and should fix that problem.
SIN – TAX!!
;-j
I just did sharing, but printer still didn’t shared. although the sharename was setted.
I have an Oki Microline 320 Turbo printer hooked up with a usb to parallel cable. When reports are done, it leaves the printer in the exact printer position. It does not set top of form. When the next report comes to that printer, the report starts in the middle of the page. How can I have the printer reset to top of page automatically?
Access Denied when I try and run this command to delete any of my printers that are network shared deployed through GPO