Learn how to a build a cloud-first strategyRegister Now

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

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
0
coolchillen
Asked:
coolchillen
  • 4
  • 3
1 Solution
 
Leo EikelmanCommented:
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
0
 
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
0
 
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

0
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!

 
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
0
 
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.
0
 
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!
0
 
JackOfPHCommented:
0
 
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?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now