We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Listing Networked Printer Connections on a Remote Computer.

ExpertAssist asked
Medium Priority
Last Modified: 2009-12-16
I have been using vbscript to list the networked printer connections on a remote computer.  The script will list the printers that are directly connected, but it will not list the networked printer connections. e.g. \\printservername\printer.  I am in the process of creating printer resource groups in Active Directory and I need to know who is connected to what printer so I can add them to the correct groups and so I can also create a logon script that will automatically map the printers on logon.  The script works fine on the local
computer and lists both directly connected printers and mapped printers.  I did turn on WHS remote scripting on the computer that I have been using to test the script.

On Error Resume Next

'open the file system object with a list of computers.
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("c:\wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
For Each strComputer In RemotePC

Wscript.Echo "Computer:" & strComputer
'Option Explicit
Dim strComputer, objNetwork, objPrinter, intDrive, intNetLetter

' Here is where objPrinter enumerates the mapped drives
Set objNetwork = CreateObject("WScript.Network")
Set objPrinter = objNetwork.EnumPrinterConnections

' Extra section to troubleshoot
If objPrinter.Count = 0 Then
WScript.Echo "No Printers Mapped "
End If

' Here is the where the script reads the array
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For intDrive = 0 to objPrinter.Count -1 Step 2
intNetLetter = IntNetLetter +1
WScript.Echo "Computer:" & strcomupter & "UNC Path " & objPrinter.Item(intDrive) & " = " _
& objPrinter.Item(intDrive +1) & " Printer : " & intDrive

Watch Question

Windows XP has a built in script that will do this for you. Try.....
cscript c:\windows\system32\prnmngr.vbs -l [-s RemoteComputer] [-u UserName -w Password]
For more information on it...

The -l (list option) is shown near the bottom of the page.
Looks like you want this in a text file so just add > C:\wslist.txt to the end of your command line.

cscript c:\windows\system32\prnmngr.vbs -l -s computername >c:\wslist.txt



I did try the prnmngr.vbs and I get the same results as the script I pasted in the original question.  What I really need is to get a list of the mapped printers.  The script I pasted in the original question accesses a list of computers in the wlist.txt and  runs the script for each printer in the wlist.txt.  The script only lists the mapped network printers on the local computer.  On the remote computers, only the directly connected printers are mapped.  The script doesn't display any printers that are mapped e.g. \\printserver\printer.  only \\localmachine\printer.

The reason for this is that connected printers are HKEY_CURRENT_USER based, not HKEY_LOCAL_MACHINE. When you run the scripts locally, they are running in your own user pofile context, therefore your connected printers show up.
When using them to look at a remote machine, it is not running under the logged on user account, therefore connected printers do not get listed.
What you might consider doing, is make the script run as a logon script the saves a textfile to a network share using %computername%.txt or %username%.txt.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
That way the user's profile is loaded and the script grabs the printers from HKEY_CURRENT_USER\Printers\Connections as well.
net use > C:\wslist.txt

If you need to run this remote use PsExec



Thanks for your help. Writing the data to a network share is a good idea.

Dark King,

Thanks for the tool PsExec tool tip.  Although, I don't plan to use it in this case, I can definitely see some uses.

Thanks again,
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.