Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to list ip addresses of printers on compuer

Posted on 2009-12-29
3
Medium Priority
?
332 Views
Last Modified: 2013-12-26
Hey Everyone,
I am trying to write a quick program that outputs a file listing the printers installed with there ip addresses.

So far this is what i have

Private Sub Form_Load()
Dim l_pr As Printer
Open "c:\PrinterINFO.txt" For Output As #1

For Each l_pr In Printers
   Print #1, l_pr.DeviceName & " - " & l_pr.Port
Next
Close #1
End
End Sub

sadly this is my output
Microsoft XPS Document Writer - Ne00:
Microsoft Office Document Image Writer - Ne01:
HP Color LaserJet 4730mfp PCL 6 - Ne02:
XX786 RICOH Aficio 2090 - Ne03:

0
Comment
Question by:JesNoFear
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 2000 total points
ID: 26146152
Have you considered using Windows Management Instrumentation (WMI)?
The example below is VBScript... but it should be fairly easy to translate to VB6.   In my case, the PortName shows the IP address of the printers
 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Printer",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Printer instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "Local: " & objItem.Local
    Wscript.Echo "Location: " & objItem.Location
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Network: " & objItem.Network
    Wscript.Echo "PortName: " & objItem.PortName
    Wscript.Echo "ServerName: " & objItem.ServerName
Next

Open in new window

0
 
LVL 2

Author Closing Comment

by:JesNoFear
ID: 31670910
Awesome! thanks
0
 
LVL 2

Author Comment

by:JesNoFear
ID: 26148958
works great, here is my code
--------------------------------------------------------------------
Open "c:\PrinterINFO.txt" For Output As #1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Printer", , 48)
For Each objItem In colItems
    Print #1, objItem.Caption & " - " & objItem.PortName
Next
Close #1
End

-----------------------------------------------------------------------------------------------------
Output:
Microsoft XPS Document Writer - XPSPort:
Microsoft Office Document Image Writer - Microsoft Document Imaging Writer Port:
HP Color LaserJet 4730mfp PCL 6 - IP_10.220.2.197
XX786 RICOH Aficio 2090 - IP_10.80.2.90
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Loops Section Overview

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question