Windows

Discover the power of Windows 7 hidden VBScript print utilities

Greg Shultz introduces you to VBScript print utilities and explains why they're an important addition to the Windows 7 operating system.

Microsoft Windows 7 comes with a host of handy command-line utilities that actually pack a lot of power. Recently a friend of mine, who has been supporting Windows XP machines for the better part of his career and is getting ready to make the move to Windows 7, asked me if Windows 7 still came with the VBScript print utilities that were first introduced with Windows XP. Fortunately for my friend, Windows 7 does, indeed, still come with those print utilities. However, because they are buried away in the bowels of the operating system, they are not easy to find if you don't know that they exist.

In this edition of the Windows Desktop Report, I'll introduce you to these VBScript print utilities and explain why they're an important addition to the Windows 7 operating system. As I do, I'll take a look at some example situations where these scripts can come in handy.

Why use scripts?

The first thing that probably came to mind when you read the introduction is "Why would you need to resort to script-based print utilities in Windows 7? Can't you perform all print tasks from Windows 7's GUI-based printer tools?" Well, there are several reasons why Microsoft has continued to provide these VBScript print utilities in Windows 7.

The answer to the second question is easy: "Yes, you can perform all printing tasks with GUI-based printer tools." The answer to the first question is twofold: First, these scripts really showcase some of the powerful features provided by Windows Script Host and Windows Management Instrumentation (WMI). Second, the scripts offer convenience and power in that they are easy to use, are customizable via command-line parameters, and can provide quick and direct access to very specific printing tasks.

For example, suppose you have a printer that is used so heavily 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 was never an 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 these scripts because they actually must be run from the Command Prompt.

The seven printer utilities, shown in Table A, are located in the C:\Windows\System32\Printing_Admin_Scripts\en-US folder, which is not listed in the path. Therefore, you must actually change to this folder in order to run the utilities. And, since these utilities are designed to be run from the command line, you need to launch them from a Command Prompt window and run them using Windows Script Host's command-line-based script host (Cscript.exe).

Table A: Windows 7's VBScript printing utilities

VBScript File

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
Pubprn.vbs Publish a printer to Active Directory

The basic syntax for running these command-line-based scripts is

cscript printutility.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.

At this point, let's take a closer look at some example situations where you might use these printer utilities. Keep in mind that I will describe only the parameters used in my example. Each one of the VBScript utilities has many more parameters than I will be able to show. Be sure to read the information in the "Learning More" section.

Prncnfg.vbs

The Prncnfg.vbs script provides you with a printer configuration utility that allows you to display and change printer configuration information. It will also allow you to rename a printer.

This printer configuration utility can come in handy in a number of different situations. For instance, suppose you want to build an inventory database of all the printers on your network. You can take advantage of the Prncnfg.vbs script's ability to display printer configuration information. To do so, you use this command syntax:

cscript prncnfg.vbs -g [-s ServerName] -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 in this command are defined in Table B.

Table B: Parameters to configure the Prncnfg.vbs script to display printer configuration information.

Parameter

Description

-g Required. Specifies that you want to display configuration information about a printer.
-s ServerName 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.

Prndrvr.vbs

The Prndrvr.vbs script provides you with a printer driver utility that allows you to list and examine printer drivers. This utility will also allow you 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, you use this command syntax:

cscript prndrvr.vbs -l [-s ServerName] [-u UserName -w Password]
The parameters used on this command line are defined in Table C.

Table C: Parameters to configure the Prndrvr.vbs script to list all the printer driver files.

Parameter

Description

-l Required. Specifies that you want to list all the drivers on a computer.
-s ServerName 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.

Prnjobs.vbs

The Prnjobs.vbs script provides you with a print job monitoring utility that allows you to pause, resume, cancel, and list print jobs. Suppose that 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 ServerName] [-p PrinterName] [-u UserName -w Password] 
The parameters used on this command line are defined in Table D.

Table D: Parameters to configure the Prnjobs.vbs script to list all the print queue.

Parameter

Description

-l Required. Specifies that you want to list all the print jobs in a print queue.
-s ServerName 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.

Prnmngr.vbs

The Prnmngr.vbs script provides you with a printer management utility that allows you to add, delete, and list printer connections. It will also allow you to set and display the default printer.

The Prnmngr.vbs script can come 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 ServerName] -m DriverName -r PortName [-u UserName -w Password]
The parameters used on this command line are defined in Table E.

Table E: Parameters to configure the Prnmngr.vbs script to add a new printer.

Parameter 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 ServerName 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.

Prnport.vbs

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

Suppose that you need to create a standard TCP/IP printer port. If you already have all the settings in hand, you can perform the operation very quickly using the Prnport.vbs script with this syntax

cscript prnport.vbs -a -r PortName [-s ServerName] -h HostAddress [-u UserName -w Password] [-o {raw -n PortNumber | lpr}] [-q QueueName] [-m{e | d}] [-i SNMPName] [-y CommunityName] [-2{e | d}]
The parameters used on this command line are defined in Table F.

Table F: Parameters to use the Prnport.vbs script to create a standard TCP/IP printer port.

Parameter

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 ServerName 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 HostAddress 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 SNMPName 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 respooling) are enabled for TCP LPR ports.

Prnqctl.vbs

The Prnqctl.vbs script provides you with a printer queue management utility that allows you to 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 that you find yourself often printing test pages, which can be a multistep operation. The neatest feature of the Prnqctl.vbs script is that it allows you to quickly print a test page right from the command line. As such, 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 ServerName] -p PrinterName [-u UserName -w Password]
The parameters used on this command line are defined in Table G.

Table G: Parameters to use the Prnqctl.vbs script to print a test page.

Parameter

Description

-e Required. Specifies that you want to print a test page.
-s ServerName 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.

Pubprn.vbs

The Pubprn.vbs script provides you with a tool that you can use to easily publish a printer to your Active Directory. To do so, you'd use the syntax:

cscript pubprn.vbs ServerName LDAP://CN=<Container>,DC=<Container>"
The parameters used on this command line are defined in Table H.

Table H: Parameters to publish a printer to Active Directory.

Parameter

Description

ServerName Optional. Specifies the name of the Windows server that hosts the printer that you want to publish. If you do not specify a computer, the local computer is used.
"LDAP://CN=<Container>, DC=<Container>" Specifies the path to the container in Active Directory Domain Services where you want to publish the printer.

Learning more

In this article you've been introduced to Windows 7's seven VBScript print utilities and gotten a glimpse of how they can be used 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 table, access Help and Support on the Start menu. When you see the Home page, type Command Reference in the Search Help box. Next, click the Command Reference Overview link (Figure A) and then scroll down until you see the seven VBScript print utilities (Figure B). Each one is a link to very detailed information on the Microsoft TechNet site.

Figure A

Figure B

What's your take?

Now that you know about Windows 7's VBScript printer utilities, will you put them to use? Have you used the printer utilities in the past? If so, what was your experience? As always, if you have comments or information to share about this topic, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

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.

4 comments
sam.wagoner
sam.wagoner

I am looking for a way to change a printer's default orientation from a command line.

Slayer_
Slayer_

I have a program for installing printers, and it runs command.com /C cscript "prnmngr.vbs" -l > c:\cfw32\temp.txt (cmd is substituted for win7 machines) Which gives a listing of all installed printers, I then search this list for which printers are installed and which need to be installed

Mark W. Kaelin
Mark W. Kaelin

Have you used the VBScript print utilities in the past? Tell your peers about the pros and the cons of using them.

Editor's Picks