Listing Networked Printer Connections on a Remote Computer.

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
oTextStream.Close
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 "
Wscript.Quit(0)
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
Next
Next

ExpertAssistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KenneniahCommented:
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]
KenneniahCommented:
For more information on it...
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnmngr.mspx?mfr=true

The -l (list option) is shown near the bottom of the page.
KenneniahCommented:
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
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

ExpertAssistAuthor Commented:
Kenneniah,

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.

ExpertAssist
KenneniahCommented:
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.
KenneniahCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KenneniahCommented:
That way the user's profile is loaded and the script grabs the printers from HKEY_CURRENT_USER\Printers\Connections as well.
Dark_KingCommented:
net use > C:\wslist.txt

If you need to run this remote use PsExec
http://www.sysinternals.com/Utilities/PsExec.html
ExpertAssistAuthor Commented:
Kenneniah,

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,
ExpertAssist
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.