Enumerating Printers and Print Capabilities

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Before you can determine how to best distribute and use your printing resources, you must have a detailed knowledge of those resources. For example, Department A might have only three printers compared with five printers in Department B. However, if the printers in Department A can print 20 pages per minute and the printers in Department B can print only 5 pages per minute, users in Department A actually have more printing capacity. Without knowing the detailed capabilities of these printers, you might erroneously conclude that Department A is short on printing capacity and thus purchase additional printers that end up going unused.

WMI includes two classes, Win32_Printer and Win32_PrinterConfiguration, which can be used to return detailed information about all the printers installed on a computer.

Scripting Steps

Listing 13.10 contains a script that retrieves printer information. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_PrinterConfiguration class.

    This query returns a collection consisting of configuration information for all the printers installed on the computer.

  4. For each printer in the collection, echo the specified properties.

    Many of these property values are returned as integers or as other values that might be difficult to interpret. Because of this, the script converts the following property values to recognizable values:

    • Orientation. If the value 1 is returned, the orientation is Portrait mode. Otherwise, the orientation is Landscape mode.
    • Paper length. Paper length is returned in tenths of a millimeter. To convert the value to inches, divide the length by 254. For example, if the value 2,794 is returned, the length is divided by 254, converting 2,794 tenths of a millimeter to 11 inches.
    • Paper width. Paper width is returned in tenths of a millimeter. To convert the value to inches, divide the width by 254. For example, if the value 2,159 is returned, width length is divided by 254, converting 2,159 tenths of a millimeter to 8.5 inches.
    • TrueType option. If the value is 1, the string "Print TrueType fonts as graphics" is echoed. If the value is 2, the string "Download TrueType fonts as soft fonts" is echoed. If the value is anything other than 1 or 2, the string "Substitute device fonts for TrueType fonts" is echoed.

Listing 13.10   Enumerating Printers and Printer Capabilities

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters =  objWMIService.ExecQuery _     ("SELECT * FROM Win32_PrinterConfiguration") For Each objPrinter in colInstalledPrinters     Wscript.Echo "Name: " & objPrinter.Name     Wscript.Echo "Collate: " & objPrinter.Collate     Wscript.Echo "Copies: " & objPrinter.Copies     Wscript.Echo "Driver Version: " & objPrinter.DriverVersion     Wscript.Echo "Duplex: " & objPrinter.Duplex     Wscript.Echo "Horizontal Resolution: " & _         objPrinter.HorizontalResolution     If objPrinter.Orientation = 1 Then         strOrientation =  "Portrait"     Else         strOrientation = "Landscape"     End If     Wscript.Echo "Orientation : " & strOrientation     Wscript.Echo "Paper Length: " & objPrinter.PaperLength / 254     Wscript.Echo "Paper Width: " & objPrinter.PaperWidth / 254     Wscript.Echo "Print Quality: " & objPrinter.PrintQuality     Wscript.Echo "Scale: " & objPrinter.Scale     Wscript.Echo "Specification Version: " & _         objPrinter.SpecificationVersion     If objPrinter.TTOption = 1 Then         strTTOption = "Print TrueType fonts as graphics."     ElseIf objPrinter.TTOption = 2 Then         strTTOption = "Download TrueType fonts as soft fonts."     Else         strTTOption = "Substitute device fonts for TrueType fonts."     End If     Wscript.Echo "True Type Option: " & strTTOption     Wscript.Echo "Vertical Resolution: " & objPrinter.VerticalResolution Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net