Printer commands in windows

Содержание
  1. Managing Printers from the Command Prompt in Windows 10 / 8.1
  2. Ready-to-Use VBS Scripts to Manage Printers in Windows
  3. How to Install a Printer Driver from the Command Line?
  4. How to Add a New Printer from the Command Prompt?
  5. Managing Default Printer Using CMD
  6. How to Create a TCP/IP Port for a Network Printer?
  7. How to Print a Test Page from the CMD?
  8. Manage Print Queues from the Command Prompt
  9. Share a Network Printer Using the Command Line
  10. How to Add a Network Printer via the Command Line?
  11. How to Remove a Printer and Its Driver from the Command Prompt?
  12. Управление принтерами из командной строки в Windows 10 / 8.1
  13. Готовые VBS скрипты для управления принтерами в Windows
  14. Установка драйвера принтера из командной строки
  15. Установка нового принтера из командной строки
  16. Управление принтером по-умолчанию
  17. Создаем TCP/IP порт для сетевого принтера
  18. Отправка на печать тестовой страницы
  19. Управление очередями печати из командной строки
  20. Включить общий доступ к принтеру из командной строки
  21. Как подключить сетевой принтер из командной строки
  22. Удаление принтера и драйвера печати из командной строки

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.

  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.

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

Читайте также:  Как установить java home linux

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

Читайте также:  Linux mount sd card

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.

Управление принтерами из командной строки в Windows 10 / 8.1

Сегодня поговорим о возможностях управления принтерами и их драйверами из командной строки, которые можно использовать в Windows 10 / 8.1 и Windows Server 2012 R2 /2016. В этой статье мы рассмотрим, как с помощью простых команд можно установить в системе новый локальный или сетевой принтер, драйвер печати, создать порт печати, отправить на печать тестовую страницу, удалить драйвер или принтер. Вы можете использовать командную строку в различных сценариях автоматической установки принтеров в заданиях SCCM, логон-скриптах групповых политик или на серверах, работающих в режиме Server Core.

Готовые VBS скрипты для управления принтерами в Windows

Для управления принтерами Microsoft разработала несколько vbs скриптов, позволяющих управлять принтерами и очередями печати, устанавливать и удалять драйвера принтеров и т.д.

Эти скрипты присутствуют во всех версиях Windows (начиная с Vista и Windows Server 2008) и находятся в каталоге C:\Windows\System32\Printing_Admin_Scripts\en-US.

  1. Вместо каталога en-US может быть другой каталог, соответствующий языку установленной системы. Для русской версии Windows это будет каталог ru-RU (полный путь C:\Windows\System32\Printing_Admin_Scripts\ru-RU);
  2. В Windows XP и Windows Server 2003 эти vbs скрипты хранятся в каталоге C:\WINDOWS\system32.

В каталоге находятся следующие vbs скрипты:

  • Prncnfg.vbs – скрипт для отображения информации о настройках принтера;
  • Prndrvr.vbs – управление драйверами принтеров (установка/удаление драйвера);
  • Prnjobs.vbs – управления заданиями печати;
  • Prnmngr.vbs – управление принтерами (в т.ч. создание и удаление принтера в системе);
  • Prnport.vbs – управление подключением к удаленному принтеру по TCP/IP порту;
  • Prnqctl.vbs – управление выполнением задания на печать;
  • Pubprn.vbs – управление публикацией принтеров в Active Directory.

Рассмотрим типовые сценарии использования этих vbs скриптов.

Установка драйвера принтера из командной строки

Предположим, вам необходимо установить на компьютере пользователя универсальный драйвер печати HP (HP Universal Printer Driver). Скачайте соответствующую версию драйвера с сайта производителя и распакуйте его в произвольный каталог (например, C:\drv\HP Universal Print Driver).

Рассмотрим параметры команды:

-а – добавить драйвер принтера;

-m «HP Universal Printing PCL 6» – имя драйвера принтера;

-i “путь” – полный путь к inf файлу драйвера.

После установки драйвера печати, он появится в свойствах сервера печати (Control Panel\Hardware and Sound\Devices and Printers ->Print Server Properties).

Установка нового принтера из командной строки

С помощью следующей команды можно установить новый принтер с именем HP5525, воспользовавшись ранее установленным драйвером печати HP Universal Printing PCL 6:

-a – устанавливается новый локальный принтер;

-p «HP5525» – отображаемое имя принтера;

-m «HP Universal Printing PCL 6» – используемый драйвер печати;

-r «lpt1:» – имя используемого локального порта печати. В этом случае печать должна осуществляться через LPT порт. Здесь может быть указан параллельный порт (LPT1:, LPT2:), последовательный (СОМ1:, COM2: — перед установкой убедитесь что данный COM порт не используется другим устройством) или USB-порт (USB001 и т.д.).

Читайте также:  Обновление для windows kb958559

Управление принтером по-умолчанию

Из командной строки вы можете выбрать какой принтер должен использоваться при печати по умолчанию. С помощью следующей команды можно вывести список всех доступных принтеров:

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

Текущий принтер по-умолчанию можно получить так:

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

Принтер по умолчанию HP Universal Printing PCL 6

Чтобы выбрать другой принтер для печати по умолчаню, выполните:

cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs» -t –р «HP5525»

Создаем TCP/IP порт для сетевого принтера

Если вы хотите подключить сетевой принтер, необходимо сначала создать для него сетевой порт (допустим ip адрес принтера 192.168.10.26):
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\Prnport.vbs» -a -r IP_192.168.10.26 -h 192.168.10.26 -o raw -n 9100
-r IP_192.168.10.26 – имя сетевого порта;

-h 192.168.10.26 – IP адрес устройства;

-o raw – тип порта (raw или lpr);

-n 9100 — номер TCP порта устройства (обычно 9100).

А потом установим в системе новый сетевой принтер:
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs» -a -p «HP5525» -m «HP Universal Printing PCL 6» -r «IP_192.168.10.26»
После окончания работы скрипта в системе появится новый принтер с именем HP5525

Отправка на печать тестовой страницы

Чтобы отправить тестовую страницу на печать на созданном ранее принтере, выполните:
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnqctl.vbs” -e -p «HP5525»

Управление очередями печати из командной строки

С помощью скрипта prnjobs.vbs вы можете просматривать задания печати в очередях. Чтобы вывести все задания печати для всех локальных принетров, выполните команду:
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnjobs.vbs” –l

Чтобы вывести задания на конкретном принтере, нужно указать его имя:

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

Для очистки очереди печати, на одном принтере выполните команду:

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

Либо можно быстро очистить все очереди для всех принтеров (так гораздо удобнее, чем вручную очищать очередь печати):

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

Включить общий доступ к принтеру из командной строки

Все новые принтеры, которое вы установили в Windows из командной строки являются локальными. Вы можете предоставить к ним общий доступ другим пользователей из графического интерфейса Windows (см. статью). Также вы можете открыть общий доступ к принетру из командной строки. Например, вы хотите дать доступ к своему общему принтеру HP5525, опубликовав его под именем HP5525_Shared. Используйте команду:

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

Чтобы отключить общий доступ к принтеру, выполните:

script «C:\Windows\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs” -t -p «HP5525» -shared

Аналогично вы можете опубликовать принтер в Active Directory:

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

Чтобы отменить публикацию в AD для принтера, используйте аргумент «-published».

Как подключить сетевой принтер из командной строки

Чтобы подключить сетевой принтер, подключенный к другому компьютеру, используйте

cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs» -ac -p “\\prnt01\hp2000”

Удаление принтера и драйвера печати из командной строки

Полный список принетров в системе можно вывести так:

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

Удалить принтер можно командой:
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs» -d -p «HP5525»
Драйвер печати удаляется так:
cscript «C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs» -d -m «HP Universal Printing PCL 6» -e «Windows x64» -v 3

В этой статье мы рассмотрели базовые операции со старыми-добрыми vbs-скриптами Microsoft, позволяющими управлять принтерами и их драйверами из командной строки в различных версиях Windows. Полный список возможностей и аргументов этих скриптов доступен в документации Microsoft или во встроенной в сами сценарии помощи (просто запустите в командной строке файл сценария без параметров).

В следующей статье мы познакомимся с новыми возможностями управления принтерами в Windows 10 / 8.1 и Windows Server 2016 / 2012 R2, которые предоставляет PowerShell.

Оцените статью