[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1472
  • Last Modified:

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

0
ExpertAssist
Asked:
ExpertAssist
  • 6
  • 2
1 Solution
 
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]
0
 
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.
0
 
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
0
 
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.
0
 
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.
0
 
KenneniahCommented:
That way the user's profile is loaded and the script grabs the printers from HKEY_CURRENT_USER\Printers\Connections as well.
0
 
Dark_KingCommented:
net use > C:\wslist.txt

If you need to run this remote use PsExec
http://www.sysinternals.com/Utilities/PsExec.html
0
 
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now