Skip navigation

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

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish