Previous Page
Next Page

Working with Win32_Printer

In this section, you are going to use the WMI Win32_Printer class. This particular WMI class is large and robust, defining more than 80 properties and implementing 7 methods. Some of its more useful properties are listed in Table 18-1.

Table 18-1. Useful Win32_Printer Properties

Property

Description

Attributes

Attributes of a Microsoft Windows printing device. Represented by a combination of flags.

Availability

Availability and status of the device. Return values are as follows: 2 = unknown, 3 = running or full power, 8 = offline.

AvailableJobSheets

Array of all job sheets available on a printer. Also used to describe the banner a printer might provide.

AveragePagesPerMinute

Print rate of the printer.

CharSetsSupported

Array of available character sets for output. Strings in this property are defined in Request for Comments (RFC) 2046 (Multipurpose Internet Mail Extensions [MIME] part 2) and in the Internet Assigned Numbers Authority (IANA) character-set registry. Examples: utf-8, us-ascii, and iso-8859-1.

Comment

String that contains a comment for a print queue. Example: color printer.

CurrentLanguage

Printer language currently being used. Examples: 1 = other, 2 = unknown, 3 = PCL, 6 = PS.

Default

Boolean. If true, the printer is the default printer on the computer.

DefaultCopies

Number of copies that are produced for one job.

DetectedErrorState

Printer error information. Examples: 1 = unknown, 2 = other, 3 = no error, 5 = no paper, 6 = low toner, 9 = jammed, 10 = offline.

Direct

Boolean. If true, the print job is sent directly to the printer. If false, the print job is spooled.

DoCompleteFirst

Boolean. If true, the printer starts jobs that are finished spooling. If false, the printer starts jobs in the order they are received.

DriverName

String. Name of the Windows printer driver.

JobCountSinceLastReset

Number of print jobs since the printer was last reset.

KeepPrintedJobs

Boolean. If true, the print spooler does not delete completed jobs.

LastErrorCode

Last error code that the logical device reports.

Local

Boolean. If true, the printer is not attached to a network.

ServerName

String. Name of the server that controls the printer.

Shared

Boolean. If true, the printer is available as a shared network resource.

ShareName

String. Share name of the print device.

Status

String. Current status. Examples: ok, error, degraded, unknown, and stopping.

workOffLine

Boolean. If true, you can queue print jobs on the computer when the printer is offline.


Just the Steps

To use the Win32_Printer class to manage a printer

1.
Create a variable to hold a WMI connection.

2.
Use GetObject and the WMI moniker to make a WMI connection.

3.
Assign the object that comes back from the WMI connection to the variable in step 1.

4.
Use the ExecQuery method to query Win32_Printer.

5.
Use For Each...Next to iterate through the printer's collection.



Previous Page
Next Page