How to Manage Printers and Printer Drivers Remotely from Command Line


A few practical examples on using RunDLL and PRNxxxx.VBS scripts for remote printer management.

The regular users do not have privileges to install a printer driver even though they can add a printer. If so, they cannot install any printers if drivers required for those printers are not installed. There are several ways to allow a user to install a printer:

  1. The user can be temporarily added to the local administrator group
  2. The system administrator can log into the computer and install the needed driver
  3. The driver and the printer can be install remotely

The first way is not good from the security point of view. The second one is not always convenient, especially when a user is on the VPN connection. The third one pretty often is the best one or even the only one way to install a printer for a user.

Microsoft provides printui.dll and five VB scripts to manage printers and drivers remotely. Both printui.dll and VB scripts can do any aspects of this job, however, their combination gets better results. All the parameters and some examples of printui.dll can be found in PrintUI.DLL User’s Guide and Reference and Rundll32 printui.dll,PrintUIEntry; information about VB scripts is in the Printer related Scripts in Windows XP and Server 2003 file. Also, the links to respective Microsoft articles are available in Appendix.

Installing a printer driver

There are some useful commands below.

ComputerName : a remote computer name (a user computer) where a printer should be installed
DriverFolderName : a name of the folder which contains the driver files
INFFileName : a name of the INF file, located in the DriverFolderName folder
DriverName : a name of driver from INFFileName
FullINFFileName : a full name of the INF file, including DriverFolderName

To list of printer drivers

cscript c:\windows\system32\prndrvr.vbs -l -s ComputerName

To add a driver

cscript c:\windows\system32\prndrvr.vbs -a -s ComputerName -h DriverFolderName -i INFFileName -m DriverName

Unfortunately, this command does not work and pretty often fails with the following error message:

Unable to add printer driver DriverName Win32 error code 87

This one works

rundll32 printui.dll PrintUIEntry /ia /c\\ ComputerName /m DriverName /h “Intel” /v “Windows 2000” /f FullINFFileName

Note: keep /h and /v parameters as they are in command above.

Interactive PowerShell script Add-PrinterDriver can make this job easier


Installing a local printer connected to TCP/IP port

There is the list of useful commands below.

ComputerName is a remote computer name (a user computer) where a printer should be installed
PrinterName is a name of printer that has to be created
IPAddress : IP address of a network printer
PortName : TCP/IP port name for printer. Usually looks like IP_xx.xx.xx.xx
DriverName : a name of printer driver. The driver must be installed

To list the installed printers

cscript c:\windows\system32\prnmngr.vbs -l -s ComputerName

It does not show any printers installed in user context

To list the installed ports

cscript c:\windows\system32\prnport.vbs -l -s ComputerName

To add a new port

cscript c:\windows\system32\prnport.vbs -a -r PortName -h IPAddress -s ComputerName -o RAW -n 9100

To install a printer

cscript c:\windows\system32\prnmngr.vbs -a -s ComputerName -m DriverName -r PortName -p PrinterName

To print a test page

cscript c:\windows\system32\prnqctl.vbs -e -s ComputerName -p PrinterName


Installing a shared network printer

Installation of a shared network printer does not work via PRNxxxx.VBS scripts. In this case rundll32 printui.dll PrintUIEntry helps out

There is the list of useful commands below.

ComputerName is a remote computer name (a user computer) where a printer should be installed. The name must start with \\ (i.e. \\COMPUTER)
PrinterName is a name of network printer that has to be created. It has to look like \\server\printer
IPAddress : IP address of a network printer
PortName : TCP/IP port name for printer. Usually looks like IP_xx.xx.xx.xx
DriverName : a name of printer driver. The driver must be installed

To install a printer

rundll32 printui.dll PrintUIEntry /in /n PrinterName /c ComputerName

To list the shared network printers

rundll32 printui.dll PrintUIEntry /ge /c ComputerName

To print a test page

rundll32 printui.dll PrintUIEntry /k /c ComputerName /n PrinterName

Note Do not forget to restart Print Spooler after using rundll32 printui.dll PrintUIEntry command

Start /WAIT sc \\ComputerName stop spooler
Start /WAIT sc \\ComputerName start spooler


Examples

Two PowerShell scripts, Add-Printer and Add-PrinterDriver can be found in Script Examples – 001. They are the working scripts; they are located together in one file because WordPress does not allow to save the .PS1 files


APPENDIX

PRNCNFG.VBS – configures or displays configuration information about a printer

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prncnfg.mspx

PRNDRVR.VBS – adds, deletes, and lists printer drivers

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prndrvr.mspx

PRNJOBS.VBS – pauses, resumes, cancels, and lists print jobs

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnjobs.mspx

PRNMNGR.VBS – Adds, deletes, and lists printers or printer connections, in addition to setting and displaying the default printer

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnmngr.mspx

PRNPORT.VBS – add, delete or list Standard TCP/IP ports

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnport.mspx

PRNQCTL.VBS – prints a test page, pauses or resumes a printer, and clears a printer queue

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnqctl.mspx

PRINTUI.DLL User’s Guide from Microsoft Corporation

http://download.microsoft.com/download/8/2/c/82cffcfa-56f6-4fc3-bfa5-80cd84793871/PrintUIUsersGuide.doc

Advertisements

12 Responses to How to Manage Printers and Printer Drivers Remotely from Command Line

  1. […] HOW TO EXECUTE POWERSHELL SCRIPTS POWERSHELL PRINTER SCRIPTS I POWERSHELL PRINTER SCRIPTS II POWERSHELL PRINTER SCRIPTS III POWERSHELL PRINTER SCRIPTS IV […]

  2. Bryan says:

    What version of Windows does this apply to? Would the methods be exactly the same on Windows 7 computers?

  3. Since it uses WMI, it should work on Windows 7. However, you may need to run it with elevated privileges.

  4. printer says:

    What’s up to every body, it’s my first pay a visit of this webpage; this web
    site contains remarkable and genuinely fine
    stuff for readers.

  5. Massimo Frison says:

    I am trying to let it work on Windows 7 64 bit.
    Everything seems to be working fine, except the “driver installation” phase (both CSCRIPT and RunDll).
    If it helps I can give more details about my specific problem

  6. Massimo Frison says:

    so I started writing carefully this post to be detailed in my question…
    …and I discovered that the command works perfectly!!

    CSCRIPT prndrvr.vbs -a -s -m “HP Universal Printing PS (v5.5.0)” -h -i

    only remark: I managed to install the driver only executing the script from the computer where I am logged on, specifying anyway the switch -s which in my script will be
    -s %COMPUTERNAME%

    In all other cases (if I try to install remotely) I get the error
    Unable to add printer driver “HP Uni…. (v5.5.0)” Win32 error code 87

    Now I will try to automate the whole procedure, than I’ll get back here

    B)

    ===============================================

    Sorry: I have deadlines, so I cannot dedicate too much time to this research. By the way this is my situation:

    about 50 machines running Win7 64bit

    where I would like to install network printers via scripting.
    If we divide the process in 4 steps:

    1. creating port (prnport.vbs)
    2. installing driver (prndrvr.vbs)
    3. installing printer (prnmngr.vbs)
    4. configuring printer (prncnfg.vbs)

    I only have problems with point 2: prndrvr.vbs

    Of course I am testing with different types of printers/drivers from a ^cmd session, either on my machine or on remote machines with the -s switch

    To this specific example the attempt is to install the driver “HP Universal Printing PS (v5.5.0)” which fails. No differences come with other drivers.

    The command

    CSCRIPT prndrvr.vbs -a -s -m “HP Universal Printing PS (v5.5.0)” -h -i

    gives me the following error…
    …gasp!!! go back to the top

  7. Thanks a bunch for sharing this with all people
    you really understand what you’re talking approximately! Bookmarked. Please also visit my web site =). We could have a link alternate arrangement between us

  8. Natalie says:

    It’s amazing designed for me to have a web page, which is good in favor of my know-how. thanks admin

  9. Merely want to tell you Now i’m grateful that i stumbled on your web site.

  10. Andy says:

    I’m executing the following via psexec: rundll32 printui.dll PrintUIEntry /ia /c \\a0193 /m brother 7860DW /h “Intel” /v “Windows 7” /f \\a0159\c$\deploy\64\brimm10a.inf

    a0193 is the remote computer i want to add the driver to, and a0159 is my workstation where the driver is located. i keep getting “The Arguments are Invalid” when the script executes.

    Can someone please tell me why?

    Thanks!

  11. Lynn says:

    It’s going to be end of mine day, however before end I
    am reading this fantastic piece of writing to improve my experience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: