Link to home
Start Free TrialLog in
Avatar of ExpertAssist
ExpertAssistFlag for United States of America

asked on

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

Avatar of Kenneniah
Kenneniah

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...
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.
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
Avatar of ExpertAssist

ASKER

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
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.
ASKER CERTIFIED SOLUTION
Avatar of Kenneniah
Kenneniah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
http://www.sysinternals.com/Utilities/PsExec.html
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