Getting Printer Port Information

I have an application that will run on about 25 different computers at my office and it needs to identify a couple particular printers on its own.  The problem is, i dont want to use the printer name as an identifyer (Printers(x).DeviceName) because some computers have had there default print name changed to something a little more friendly (ex. "Deskjet 5600" changed to "Color Printer").  So i thought i would use the "port name" because i thought that would be consistant (they are all network printers on TCP/IP printer ports ex. "IP_10.0.0.70").  The port names as they are listed in the printer properties dialog are nicely named but when i call "Printers(x).Port", it returns ne00, ne01 ect. which of course is not consistant from one workstation to the next.

Does anyone know how to get the "friendly" port names, as seen in the printers properties dialog? or know any other way to identify a particular printer without knowing it's name?

Thanks,
Matt
coolchillenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leo EikelmanDirector, IT and Business DevelopmentCommented:
Try this code.  I don't know if this will work as I used it to compare printer names but it might for IPs.

Dim prt As Printer

For Each prt In Printers

If prt.Port = 10.0.0.70 Then 'You would compare to IP address instead

Set Printer = prt

strDeviceName = prt.DeviceName
strDriverName = prt.DriverName
strPort = prt.Port

Exit For

End If
Next prt

Set prt = Nothing

Report.SelectPrinter strDriverName, strDeviceName, strPort

Report.PrintOut False



strDeviceName should hold the friendly name of the printer.


Leo
coolchillenAuthor Commented:
Thanks Leo,

Unfortunatly prt.Port returns something like LPT1 or ne01 not the "IP_10.0.0.70" port name found in the printer properties dialog on the port tab that i thought i could use as an identifier.

The problem is that depending on what order different printers were setup on an individual workstation, the printer i want could be ne01 on one system and ne04 on another...they all have the "IP_10.0.0.70" port checked in the printer properties dialog, i just can seem to extract that from a Printer object.

Matt
JackOfPHCommented:
   Dim RemoteComputer as String
    Dim WMIService as Object
    Dim PrinterList as Object
    Dim PrinterInstance as Object

    RemoteComputer = "."   'Replace the . with the name of the remote PC
    Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & RemoteComputer & "\root\cimv2")
    Set PrinterList = WMIService.ExecQuery("Select * from Win32_Printer")
    For Each PrinterInstance In PrinterList
        MsgBox PrinterInstance.Sharename
    Next
    Set PrinterList = Nothing
    Set WMIService = Nothing

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

coolchillenAuthor Commented:
wow, i love the enthusiasm Jack...man, you triggered some delusions of granger in my head...but it will have to wait for version 2 of may app...and until the WMI reference book i just ordered comes in.

I was looking for a more "no networking" based solution...but your way seems way cooler.  I didn't find alot of good reference to the WMI so i ordered a book (i'm kind of a noob).  I see that your example uses the current user authentication credentials to access the remote machine...when i put my current login/password into the remote system i get an "automation error".  If you got another tip to get me a step further, that would be great, otherwise i'm going to have to hold off on this route right now (even though it seems totally cool) because of time constraints but thanks again. (and thanks for motivating me to get some good reference material...finaly picked up a book on the win32 api as well)

Again, the challenger here is to identify a common network printer on multiple systems that have the same network printer configured with a different name on each system.

thanks Jack,
matt
JackOfPHCommented:
Dim devlist as object
Dim dev as object
Set devlist = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("Select * from Win32_Printer")
For Each dev In devlist
    MsgBox "Monitor: " & dev.ShareName
Next
devlist = Nothing

I try this without a network connected in my P.C. and it returns the same.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
coolchillenAuthor Commented:
sweat, that did the trick...except i used the .PortName property instead of the .ShareName property.  Interestingly, "devlist = nothing" returns "Object doesn't support this property or method" every time.

Also, i am unfamilior with this WMI, if you have any recommended references, i would appreciate the clue.

Thanks Jack!
JackOfPHCommented:
coolchillenAuthor Commented:
:) oh ya, i've been here, me and msdn have sort of a "love hate" relationship.

Really, this and vb.net msdn is all you need?  How come 95% of the reference material i find about this "WMI" looks alot like C to me?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.