Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows 10 / Managing Printers from the Command Prompt in Windows 10 / 8.1

April 19, 2023 Windows 10Windows 8Windows Server 2012 R2

Managing Printers from the Command Prompt in Windows 10 / 8.1

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.

Contents:
  • 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.

  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.

vbs script for manage printers and drivers in windows 8

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"

install printer driver from command promptLet’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).

list of installed print drivers in windows

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:"

install printer from cmd in windows 8/2012

-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 Default Printer Using CMD

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.

just installed printer apear in 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”

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.

18 comments
3
Facebook Twitter Google + Pinterest
previous post
How to Enable Access-Based Enumeration (ABE) on Windows Server?
next post
Unable to Start or Connect to Virtual Disk Service in Disk Management

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

How to View and Change BIOS (UEFI) Settings...

September 13, 2023

18 comments

Chris November 23, 2016 - 7:03 pm

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

Reply
admin November 30, 2016 - 7:05 am

You can try to add shared network printer using this command:

cscript prnmngr.vbs -ac -p “\\server\printer1”

Reply
snow February 1, 2019 - 1:06 pm

Is it possible to add a user code in the printer configuration using command line ?

Reply
admin February 8, 2019 - 5:16 pm

I didn’t understand your task…

Reply
Smurf February 14, 2019 - 4:31 am

To change the printer IP port you can use the command:
Prncnfg.vbs -t -p PRINTENAME -r PORTNAME

Reply
Leoncio August 9, 2019 - 12:45 pm

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?

Reply
BinhBNT November 28, 2019 - 2:54 am

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.

Reply
Naveen February 12, 2020 - 3:50 pm

‘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

Reply
admin February 13, 2020 - 12:28 pm

There is a typo in the article; replace the script command with cscript

Reply
bakemono July 17, 2020 - 10:16 am

is there a way to fill the location field ?

Reply
BAKEMONO July 17, 2020 - 10:01 pm

with powershell : set-printer -name “xxx” -location “xxx”

Reply
biloo August 25, 2020 - 1:52 pm

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

Reply
McNulty March 30, 2021 - 6:27 am

Is it possible, add printer with config file with .cfm?

Reply
JMAN54 November 30, 2021 - 8:02 pm

Printer adds fine and visible by apps but doesnt show up in “printer and scanners” list in settings. WIN10 Home.

Reply
JMAN54 November 30, 2021 - 8:18 pm

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

Reply
PRanciskus sutris January 19, 2022 - 2:02 am

I just did sharing, but printer still didn’t shared. although the sharename was setted.

Reply
MIKE RYLL April 21, 2022 - 5:41 pm

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?

Reply
Todd Goodsite October 26, 2022 - 3:30 pm

Access Denied when I try and run this command to delete any of my printers that are network shared deployed through GPO

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Booting Windows 7 / 10 from GPT Disk on BIOS (non-UEFI) systems
  • Removable USB Flash Drive as Local HDD in Windows 10 / 7
  • How to increase KMS current count (count is insufficient)
  • How to Disable UAC Prompt for Specific Applications in Windows 10?
  • How to Connect L2TP/IPSec VPN Server From Windows
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Outlook Does Not Display Images in Email
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top