Printers optimize

Don't overlook these Windows XP VBScript print utilities

How and why you should use print utilities

Among Windows XP’s many new command line tools are six print utilities written in VBScript. These clever little scripts, listed in Table A, make it easy for you to quickly query and manage printers as well as perform many other common printing tasks. Since Microsoft hasn’t really provided command line tools (let alone printer utilities) written in VBScript with an operating system before, they’re easy to overlook. However, these utilities add some really useful features to Windows XP. I’ll introduce you to Windows XP’s six command line print utilities and explain why they’re an important addition to the operating system. As I do, I’ll offer some example situations of when these scripts might come in handy.
Table A
Name What it does
Prncnfg.vbs  Printer configuration
Prndrvr.vbs Printer driver configuration
Prnjobs.vbs Print job monitoring
Prnmngr.vbs Printer management
Prnport.vbs Printer port management
Prnqctl.vbs Printer queue management
Windows XP’s command line printing utilities

Why use the command line?
The first thing that probably came to mind when you read the introduction is, “Why would you need command line print utilities in Windows XP? Can’t you perform all print tasks from Windows XP’s GUI-based Printer and Faxes tool?” Well, the answer to the second question is “Yes.” You can perform all printing tasks from Windows XP’s GUI-based Printer and Faxes tool. However, the answer to the first question is more complex. There are several reasons why Microsoft decided to provide command line print utilities with Windows XP.

The first reason is that these scripts really showcase some of the powerful features provided by Windows Script Host and Windows Management Instrumentation (WMI). Another reason is that because these command line print tools are written in VBScript, they add a whole new dimension to Windows XP’s scripting capabilities. Crafty scripting wizards can use them as models for exercising more advanced control of an output mechanism from within Windows Script Host-based scripts. The third reason is convenience, since these command line printing utilities provide quick and direct access to very specific printing tasks that are within the Windows XP GUI but that may be buried deep within a dialog box somewhere. And, best of all, these command line printing utilities allow you to remotely access and control network printers.

Windows Management Instrumentation
Windows Management Instrumentation, or WMI for short, is the Microsoft implementation of Web-Based Enterprise Management (WBEM), an industry initiative to establish standards for accessing and sharing management information over an enterprise network. The integration of WMI with Windows Script Host adds a very powerful instrument to the operating system, where it’s easily accessible.

Now, when you combine all these reasons and focus them on a specific task, you can really grasp the power and benefits that having command line access to print utilities brings to the table. For example, suppose you have a printer that is so heavily used that it frequently needs to have its ink cartridges replaced. Rather than shutting down the printer and alerting everyone that you’ll be replacing the ink cartridges, you could create and run a customized script that temporarily puts the printer in offline mode, during which users could still send print jobs to the print queue. When you’re done replacing the ink cartridges, you could run another customized script that puts the printer back online, at which time printing will continue as though there had been no interruption.

Running the printer utilities
Before we actually begin examining these printer utilities, let’s take a moment to look at how you run them. It’s important to understand that running the printer utilities can be a bit tricky due to the terse rules governing command line scripts.

To begin with, the six printer utilities are located in the systemroot\system32 folder, which on most Windows XP installations is C:\Windows\System32. Now, even though this folder is listed in the path by default, you must actually change to this folder in order to run the utilities. And, since these utilities are designed to run from the command line, you’ll need to launch them from a command prompt, and you must run them using Windows Script Host’s command line script host (Cscript.exe).

The basic syntax for running these command line scripts is:
Cscript utility.vbs parameters

Furthermore, if any of the information contained in the parameters section contains spaces, such as My Computer, you must enclose that text in quotation marks.

Prncnfg.vbs
The Prncnfg.vbs script provides a printer configuration utility that lets you display and change printer configuration information. You can also use it to rename a printer.

This printer configuration utility comes in handy in a number of different situations. For example, suppose you want to build an inventory database of all the printers on your network. You could sue the Prncnfg.vbs script’s ability to display printer configuration information. This is the command syntax:
cscript prncnfg.vbs -g [-s RemoteComputer] -p PrinterName [-u UserName -w Password]

You could then use the redirection symbols on the actual command line to compile the output into a text file that you could later import into a database or a spreadsheet. The parameters used on this command line are detailed in Table B.
Table B
Parameter Required or optional Description
-g Required Specifies that you want to display configuration information about a printer.
-s RemoteComputer Optional Specifies the name of the remote computer sharing the printer. If you do not specify a computer name, the local computer is used.
-p PrinterName Required Specifies the name of the printer about which you want to display information.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
Parameters to configure the Prncnfg.vbs script to display printer configuration information

Prndrvr.vbs
The Prndrvr.vbs script provides a printer driver utility that lets you list and examine printer drivers. You can also use it to delete and add printer drivers.

If you’re troubleshooting a printer problem that could possibly be linked to outdated or missing printer drivers, you can use the Prndrvr.vbs script to quickly build a list of all the files that make up the printer driver, which you could then use for comparison. To do so, use this command syntax:
cscript prndrvr.vbs-l [-sRemoteComputer] [-uUserName-wPassword]

The parameters used on this command line are detailed in Table C.
Table C
Parameter Required or optional Description
-l Required Specifies that you want to list all the drivers on a computer.
-s RemoteComputer Optional Specifies the name of the remote computer sharing the printer. If you do not specify a computer, the local computer is used.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
Parameters to configure the Prndrvr.vbs script to list all the printer driver files

Prnjobs.vbs
The Prnjobs.vbs script provides a print job monitoring utility that lets you pause, resume, cancel, and list print jobs. For example, suppose there are a number of network printers to which you can print, and you have an urgent print job. You can use the Prnjobs.vbs script to browse around for the least busy printer. To do so, you’d use this command syntax:
cscript prnjobs -l [-s RemoteComputer] [-p PrinterName] [-u UserName -w Password]

The parameters used on this command line are detailed in Table D.
Table D
Parameter Required or optional Description
-l Required Specifies that you want to list all the print jobs in a print queue.
-s RemoteComputer Optional Specifies the name of the remote computer sharing the printer. If you do not specify a computer, the local computer is used.
-p PrinterName Optional Specifies the name of the printer whose print queue contains the jobs you want to list. If you do not specify a printer, then all jobs in all print queues are listed.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer about which you want to display print job information. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
Parameters to configure the Prnjobs.vbs script to list all jobs in the print queue

Prnmngr.vbs
The Prnmngr.vbs script provides a printer management utility that lets you add, delete, and list printer connections. You can also use it to set and display the default printer.

The Prnmngr.vbs script comes in handy if you need to quickly add a new network printer connection to a group of computers. You could create a script or a batch file that automates the installation procedure via the Prnmngr.vbs script. To do so, you’d use the command syntax:
cscript prnmngr.vbs -a -p PrinterName [-s RemoteComputer] -m DriverName -r PortName [-u UserName -w Password]

The parameters used on this command line are detailed in Table E.
Table E
Parameter Required or optional Description
-a Required Specifies that you want add a printer.
-p PrinterName Required Specifies the name of the printer that you want to add.
-s RemoteComputer Optional Specifies the name of the remote computer to which you want to add a printer. If you do not specify a computer, the printer is added to the local computer.
-m DriverName Required Specifies the name of the driver for the local printer you want to add.
-r PortName Required Specifies the port to which the printer is connected. If this is a parallel or a serial port, use the ID of the port (for example, LPT1 or COM1). If this is a TCP/IP port, use the port name that was specified when the port was added.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer to which you want to add a local printer. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
Parameters to configure the Prnmngr.vbs script to add a new printer

Prnport.vbs
The Prnport.vbs script provides a printer port management utility that lets you create, delete, and list standard TCP/IP printer ports. It also allows you to display and change port configuration.

For example, suppose you needed to create a standard TCP/IP printer port. You could go to the Printers and Faxes tool and run the Add Standard TCP/IP Printer Port Wizard, but that would require a number of steps. If you already have all the settings in hand, you can perform the operation much more quickly by using the Prnport.vbs script with this syntax:
cscript prnport.vbs -a -r PortName [-s RemoteComputer] -h IPAddress [-u UserName -w Password] [-o {raw -n PortNumber | lpr}] [-q QueueName] [-m{e | d}] [-i IndexName] [-y CommunityName] [-2{e | d}]

The parameters used on this command line are detailed in Table F.
Table F
Parameter Required or optional Description
-a Required Specifies that you want to create a standard TCP/IP port.
-r PortName Required Specifies the port to which the printer is connected.
-s RemoteComputer Optional Specifies the name of the remote computer to which you want to add the port. If you do not specify a computer, the port is added to the local computer.
-h IPAddress Required Specifies the IP address you want to assign to the port.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer on which you want to create a standard TCP/IP printer port. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
-o {raw -n PortNumber | lpr} Optional Specifies which protocol the port uses: TCP raw or TCP LPR.
-q QueueName Optional Specifies the queue name for a TCP raw port.
-m{e | d} Optional Specifies whether SNMP is enabled. The parameter e enables SNMP. The parameter d disables SNMP.
-i IndexName Optional Specifies the SNMP index, if SNMP is enabled.
-y CommunityName Optional Specifies the SNMP community name, if SNMP is enabled.
-2{e | d} Optional Specifies whether double spools (also known as re-spooling) are enabled for TCP LPR ports.
Parameters to use the Prnport.vbs script to create a standard TCP/IP printer port

Prnqctl.vbs
The Prnqctl.vbs script provides a printer queue management utility that lets you pause or resume a printer, as well as to clear a printer queue. It also allows you to print a test page on a printer.

When troubleshooting printer problems, chances are you’ll often print test pages, which can take several steps. The neatest feature of the Prnqctl.vbs script is that it allows you to quickly print a test page right from the command line. Thus, if you were to create a simple script that automates the Prnqctl.vbs script, you could print a test page just by double-clicking an icon. To do so, you’d use the syntax:
cscript prnqctl.vbs -e [-s RemoteComputer] -p PrinterName [-u UserName -w Password]

The parameters used on this command line are detailed in Table G.
Table G
Parameter Required or optional Description
-e Required Specifies that you want to print a test page.
-s RemoteComputer Optional Specifies the name of the remote computer sharing the printer on which you want to print a test page. If you do not specify a computer, the local computer is used.
-p PrinterName Required Specifies the name of the printer on which you want to print a test page.
-u UserName
-w Password
Optional Specifies an account with permissions to connect, via Windows Management Instrumentation (WMI) services, to the computer sharing the printer on which you want to print a test page. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
Parameters to use the Prnqctl.vbs script to print a test page

Learning more
I’ve introduced you to Windows XP’s six command line print utilities and offered a glimpse of how you can use them to solve common problems. However, the examples I’ve shown here represent only a small fraction of the features that these scripts offer. To learn more about all the features these scripts bring to the Windows XP operating system, access the Help and Support Center and click the Use Tools link under the Pick A Task heading. When you see the Tools page, scroll through the Tools list and select the New Command-Line Tools link, as shown in Figure A.

Figure A
You can find more detailed instructions for each of the six command line print utilities in the Help and Support Center.


 

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

5 comments
mirv550
mirv550

How easily could these vb scripts be used to create a print job scheduler?

cjtforde
cjtforde

Start, Printers and Faxes, \\server\printer1. If I double click \\server\printer1 I get all the jobs. How do I direct this output to a file in a dos bat file? Colin

tpdeiley
tpdeiley

Great tip!! Unfortunately, all of the tables as well as Figure A were truncated on the right side, making it difficult to read all of the material. I'm running IE6 v6.0.2900 on WinXP SP3.

SpuddyBuddy
SpuddyBuddy

I have been looking for long time for stuff to do this and was in the midst of learning PowerShell in the hopes of doing exactly what these scripts do. Being able to flush a specific queue from the command is a lifesaver for me (I manage busy print servers) especially since I can use the prnqctl script to automate flushing of the queues that frequently "pile up" with print jobs. Thank you, thank you, thank you. P.S. Why couldn't Microsoft have documented these? I did a search of Microsoft's online Knowledgebase and came up with nothing relating to these scripts.

robo_dev
robo_dev

A VBScript workaround was the only way I could print. VBScript is very cool, and even fun to program. My personal favorite is the script below that makes the keyboard lights flash in sequence.....(remove the extra CRLFs inserted by this forum post). Set WshShell = CreateObject( "WScript.Shell" ) Randomize counter = 0 While counter < 150 random = Int( 3 * Rnd + 1 ) Select Case random Case 1 WshShell.SendKeys "{CAPSLOCK}" Case 2 WshShell.SendKeys "{SCROLLLOCK}" Case else WshShell.SendKeys "{NUMLOCK}" End Select WScript.Sleep 100 counter = counter + 1 WEnd