Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


List Printers

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2989
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> List Printers
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 List Printers - 5/13/2005 4:12:53 AM   
  hackerjack

 

Posts: 1
Score: 0
Joined: 5/12/2005
From:
Status: offline
I liked Know? -> How to make script for list local printers in listbox using vbscript.
Thank you!
 
 
Post #: 1
 
 Re: List Printers - 5/13/2005 6:06:28 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
dont know about the listbox part, but here are a couple of ways to list printers:
with wmi

      
with the wscript.network object

      

(in reply to hackerjack)
 
 
Post #: 2
 
 Re: List Printers - 5/13/2005 8:22:30 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Thanks for the info, i used it and modified it a little and made it to where it will create an output file. All you have to do is create a txt file named computers.txt where ever the script is located that contains a list of computer names that you want to get the printer info for. Run the script after you create the text file, and it will create a file called printers.txt that contains all of the printers that are installed on each of your computers in your file

Here is the code:
Option Explicit
On Error Resume Next
Dim fso, src, dest, ts, output, temp, groups, user,WshShell,objWMIService,colInstalledPrinters,objPrinter
Set fso = CreateObject("Scripting.FileSystemObject")
src = "computers.txt"
dest = "printers.txt"

If Not fso.FileExists(src) Then
WScript.Echo "File: """& src & " cannot be found."
Else
Set ts = fso.OpenTextFile(src,1)
Set output = fso.CreateTextFile(dest,True)
Do Until ts.AtEndOfStream
temp = ts.ReadLine
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & temp & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
output.WriteLine "Printers currently installed on " & temp
output.WriteLine " "

For Each objPrinter in colInstalledPrinters
output.WriteLine string(2,vbTab) & objPrinter.name

Next

output.WriteLine
Loop
End If


Hope this helps some of you

(in reply to hackerjack)
 
 
Post #: 3
 
 Re: List Printers - 5/13/2005 8:31:07 AM   
  Coquito

 

Posts: 29
Score: 0
Joined: 4/20/2005
From: USA
Status: offline
royb5000
your script does'nt list ALL the printers the user is mapped to. When run on the local machine I get everything, when run on a remote machine not all.

Try your script with this if you can:

Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
Wscript.Echo colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
Next

(in reply to hackerjack)
 
 
Post #: 4
 
 Re: List Printers - 5/13/2005 8:39:16 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
I haven't tried it your way yet, but when i run it my way on one of our servers or another workstations i get all of the connections. I have a server that has over 90 printers installed on it and it shows all of them. What is the difference between your code and mine? Not trying to be argumentative, just curious because i am a newbie at scripting

(in reply to hackerjack)
 
 
Post #: 5
 
 Re: List Printers - 5/13/2005 8:42:53 AM   
  Coquito

 

Posts: 29
Score: 0
Joined: 4/20/2005
From: USA
Status: offline
I need to list all the printers being used by a workstation. When I run the first script I dont get all the printers just a few, When I run the script I showed you I get all printers.

I think one script shows you installed printers and the other shows you printer connections.

I need printer connections.

Are you running the script remotely?

(in reply to hackerjack)
 
 
Post #: 6
 
 Re: List Printers - 5/13/2005 8:52:15 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
I am sitting at my desktop on an AD environment, and i put the list of computers in my txt file and then run the file i get all of the installed printers and printer connections, which in my mind is a printer that is installed on another station or server and is shared. I can do this to my local computer or a server that is in another building and i am still getting all of the printers, or even the station sitting next to me. Not sure what is going on with yours.

(in reply to hackerjack)
 
 
Post #: 7
 
 Re: List Printers - 5/13/2005 9:28:50 AM   
  Coquito

 

Posts: 29
Score: 0
Joined: 4/20/2005
From: USA
Status: offline
No AD here :(

I wonder if thats the problem.

(in reply to hackerjack)
 
 
Post #: 8
 
 Re: List Printers - 5/15/2005 5:01:29 PM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Could be, i am not sure if that matters or not.

(in reply to hackerjack)
 
 
Post #: 9
 
 Re: List Printers - 5/20/2005 6:14:44 AM   
  Coquito

 

Posts: 29
Score: 0
Joined: 4/20/2005
From: USA
Status: offline
ExecQuery vs EnumeratePrinterConnections??

This script gives me different results from the one listed above:

On error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\workstations.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
' Wscript.Echo strNextLine
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
Wscript.Echo strNextLine, colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
Next
Loop


Thank you all for your help.

(in reply to hackerjack)
 
 
Post #: 10
 
 Re: List Printers - 5/20/2005 9:57:04 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
In short, EnumeratePrinterConnections (of WshNetwork object) will only enumerate printers locally on the machine from which the script executes. The " ExecQuery" (of WMI) can be specified to connect to remote machines. WMI also supports other attributes and methods that the Wshnetwork object doesn't support. Depending on what you want (logon scripts or remotely check printers on other machines), you have a choice. Just remember WMI isn't "better" because it allows binding to remote machines; it all depends on what you intend to do.

(in reply to hackerjack)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> List Printers Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts