How Can I List All the Printers on a Remote Computer?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I list all the printers – both local printers and network printers – on a remote computer?

-- CH

SpacerHey, Scripting Guy! AnswerScript Center

Hey, CH. You know, back when he worked at the University of Washington the Scripting Guy who writes this column was asked to speak at a symposium being held as part of a conference on computers and education. To say this was a last-minute invitation would be an understatement; in fact, our hero had to start putting together his talk on the plane ride from Seattle to Florida, then finish it when he reached the convention center. When he arrived at the symposium itself, he discovered that his fellow speakers were hardly as harried as he was. Their secret: instead of creating a new talk for the symposium they decided to just deliver talks that they were already giving at the conference. In other words, they were going to give the exact same talk on two different days, but to two different audiences (or so they hoped).

Note. As a matter of fact it was a very interesting symposium, if only because the future Scripting Guy was the only person on the panel who had a talk even remotely connected to the topic. Needless to say, it proved to be the lowest-rated session at the conference. (And, let’s face it: being voted the most-boring and least-useful session at an academic conference isn’t easy.)

Now, if this future Scripting Guy was smart he would have learned that clever people can do twice the work with half as much effort. Your question, CH, is a good example of that. Because you specifically asked about listing printers on a remote computer, a smart person would write a column about that, then come back a few months later and reprint the column, only this time telling people how to list printers on the local computer. (And a smart person could get away with that because the two scripts are all-but identical.)

Of course, as people who read this column know, the Scripting Guy responsible for all this isn’t particularly smart. Instead of writing two separate columns he could only come up with one, thanks to a script that lists the printers on either a remote computer or a local computer:

strComputer = "atl-ps-01"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter in colPrinters
If objPrinter.Attributes And 64 Then
strPrinterType = "Local"
strPrinterType = "Network"
End If
Wscript.Echo objPrinter.Name & " -- " & strPrinterType

As you can see, we begin by assigning the name of the remote computer (in this case, atl-ps-01) to a variable named strComputer. What if we did want to list the printers on the local machine? No problem, and no need to read a separate column, either. Instead, just assign strComputer the name of the local machine, or assign it a dot (WMI shorthand for the local computer):

strComputer = "."

After connecting to the WMI service on the desired computer, we then issue the following query, a query that returns a collection of all the printers installed on the computer:

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

If you weren’t sure just how … smart … the Scripting Guy who writes this column really is, well, what comes next should help convinced you. CH only asked for a list of printers, both local and network; however, no one mentioned whether or not the script could specify which printers were which. That could have been a whole ‘nother column; instead, we simply added a few lines of code that will make that distinction for you.

To make that distinction we first set up a For Each loop that loops through the collection of printers. Inside that loop the very first thing we do is execute this line of code:

If objPrinter.Attributes And 64 Then

What we’re doing here is checking the bitmask property Attributes to see whether bit 64 has been set. If it has, then we know that this is a local printer; in that case we set the value of the variable strPrinterType to Local:

strPrinterType = "Local"

If bit 64 has not been set then this must be a network printer; consequently we assign strPrinterType the value Network:

strPrinterType = "Network"

Two notes about this process. First, we aren’t going to talk about bitmask attributes today; for a reasonably good explanation of these babies take a look at this section of the Microsoft Windows 2000 Scripting Guide..

Second, you might be wondering why we didn’t just check the values of the Win32_Printer properties Local and Network; after all, isn’t the sole purpose of those properties to tell you whether a printer is a local printer or a network printer? Yes it is, and using these two properties is a bit easier and a bit more straightforward than using the Attributes property. However, the Local and Network properties are supported only on Windows XP and Windows Server 2003. By using the Attributes property we were able to create a generic script that will work on any version of Windows that supports WMI.

Which, come to think of it, means we missed out on yet another column: How Can I Determine Printer Types on a Windows 2000 Computer?

Sigh ….

All we have left to do now is echo back the printer name and the printer type:

Wscript.Echo objPrinter.Name & " -- " & strPrinterType

And that should do it.

Incidentally, a professor from the UW happened to attend the symposium where the future Scripting Guy spoke. As she told him the following day, she was shocked, absolutely shocked that the Scripting Guy had poked fun at the university. However, she added, “Seeing as how you’re not a professor and really not all that smart I’m not going to report you to anyone.” You can imagine how gratified this Scripting Guy was to hear that. (Editor’s Note: People at Microsoft say pretty much the same things about this Scripting Guy. At least he’s consistent.)

Comments (8)

  1. says:

    Hey scripting guy,

    I have used the steps discribed in your article to help me develop a diagnosis tool for helpesk

    And I have problems when retrieving network printers from a remote host, it works only if I use logged in users credentials :

    Is there a trick to bypass this limitation?


  2. ThomMck says:

    Nice script.

    You could have prevented another article by letting people specify the tarcget computer as an argument to the command line!

    I changed line one to

    strComputer = WScript.Arguments.Item(0)

    Now when I run the script I can type

    c:Scriptsprinters-list.vbs" <PCName>


    c:Scriptsprinters-list.vbs" .

    c:Scriptsprinters-list.vbs" DC01

    c:Scriptsprinters-list.vbs" PC123

    Unfortunately, I've tried running this against remote computers and it only gives me the locally installed ones, not ones on a network share 🙁

  3. mypcmag29 says:

    Nice article….It is very informative….thanks…..

    <a href="…/a>

  4. zMan says:

    From what I know of the Printer Object in WMI. It only provides the Printers of the person whose credentials are being used to run the query.

    I'm pretty sure there is a way to query the Registry for 'all' printers that are assigned on the computer regardless of who has logged in.

  5. Karmana says:

    Hey Scripting Guy!  (Had to say it…)  Would it be possible to see how you would change this script into an IT administrative tool that accomplishes:

    -List all installed printers on ALL computers on the network, under ANY user's login

    We're changing from an old print server, where printers were manually added by IP, or in some cases, added via logon scripts, to a 2008R2 print server, where we intend to push them out via GPO.  So I need to ID every printer each user currently has, then install the same printers (though from the new network location) BEFORE we retire the old print server.



  6. nag says:

    how to write the code to get the list of printer object that is connected with lan

  7. Sajee1 says:


    I am bit new to automation i just want to know how to query the Printer remotely in bulk and rename it if discrepenacy is found

  8. Ben Worrell says:

    I’m running on a 32bit Windows 7 computer and when I run this screen for my computer it works fine. But when I run for any other PC on the network it only returns that computer’s local printers not the network printers

    Any Suggestions?

Skip to main content