VBScript: List installed printers list


Today I had to get the list of printer drivers installed on various servers. I wrote a quick and dirty script to get the printer list.

If you want to use this, copy the following script text and paste it in Notepad. Save it as “PrinterList.vbs”. Run it as,

C:> CSCript PrinterList.vbs <Your Server Name>

‘**************************************************************************
‘ Script Name: PrinterList.vbs
‘ Parameter: Computer Name
‘ Syntax: CScript PrinterList.vbs <Computer Name>

‘ Written By: Anand Venkatachalapathy
http://anandpv.spaces.live.com
‘**************************************************************************

Dim strComputer, i
Dim objWMIService, colInstalledPrinters

‘If there are no arguments pass, quit the script
If WScript.Arguments.Count = 0 Then
    WSCript.Echo "No Server/computer name specified…"
    WScript.Echo "Syntax: CScript PrinertList.vbs <ComputerName>" & vbCrLf
    WSCript.Echo "Example: CScript PrinterList PrintServer1"
    WScript.Quit
End If

strComputer = WScript.Arguments(0)

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterDriver")

i = 1

WScript.Echo strComputer & ": Installed Printer Drivers…"
WScript.Echo "———————————————————-"
For each objPrinter in colInstalledPrinters
    Wscript.Echo i & ": " & objPrinter.Name
    i = i + 1
Next

Set colInstalledPrinters = Nothing
Set objWMIService = Nothing

‘**************************** End of Script ************************

Keywords: List installed printer drivers, List printers, Printer List

Advertisements

2 thoughts on “VBScript: List installed printers list

  1. Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)
    Set colInstalledPrinters = objWMIService.ExecQuery _
    (“Select * from Win32_PrinterDriver”)

    this script is stuk in this line

    1. Changing it to the following worked for me on windows XP
      Set objWMIService = GetObject(“winmgmts:” _
      & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s