Home
Interests
Photos
Favorites

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

A. I created the following script, which you can download at
http://list.windowsitpro.com/t?ctl=1F48E:1EDFC , 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
----

Copyright 2006, Penton Media, Inc.  All Rights Reserved.

Questions or problems regarding this web site should be directed to abeckman@outdoorssite.com.

Copyright 2008 Art Beckman. All rights reserved.

Last Modified: March 9, 2008