Subscribe to Windows IT Pro
January 30, 2006 12:00 AM

How can I use a Windows Management Instrumentation (WMI) script to list printers?

Windows IT Pro
InstantDoc ID #49225
Rating: (1)

A. I created the following script, which you can download here , that makes a WMI call and lists details about the printers known on the system:

Option Explicit
Dim objWMIService, objPrinter, colItems, strComputer

strComputer ="."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & 
  "\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")

' On Error Resume Next
For Each objPrinter In colItems
   Wscript.Echo "DeviceID: " & objPrinter.DeviceID 
   Wscript.Echo "Caption: " & objPrinter.Caption 
   Wscript.Echo "ServerName: " & objPrinter.ServerName 
   Wscript.Echo "ShareName: " & objPrinter.ShareName 
   Wscript.Echo "DriverName: " & objPrinter.DriverName 
   Wscript.Echo "Default: " & objPrinter.Default
Next

WScript.Quit
Here's an example of the script's output.
DeviceID: Tektronix Phaser 850DP
Caption: Tektronix Phaser 850DP
ServerName:
ShareName: ColorPrinter
DriverName: Tektronix Phaser 850DP
Default: True
----
DeviceID: Microsoft Office Document Image Writer
Caption: Microsoft Office Document Image Writer
ServerName:
ShareName: Printer2
DriverName: Microsoft Office Document Image Writer Driver
Default: False
----
DeviceID: Adobe PDF
Caption: Adobe PDF
ServerName:
ShareName: Printer3
DriverName: Adobe PDF Converter
Default: False
----
DeviceID: \\savdaldc01.savilltech.com\CWIS
Caption: \\savdaldc01.savilltech.com\CWIS
ServerName: \\savdaldc01.savilltech.com
ShareName: CWIS
DriverName: Xerox DocuPrint N2125 PS
Default: False
----

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.