Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


Return to article

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

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
----






Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement