Link to home
Start Free TrialLog in
Avatar of JesNoFear
JesNoFearFlag for United States of America

asked on

How to list ip addresses of printers on compuer

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:

ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

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
Avatar of JesNoFear

ASKER

Awesome! thanks
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