• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3096
  • Last Modified:

List printers installed on remote pc

Hello,

I'm trying to figure out how to get a listing of the printers that would be installed on a remote pc using vb. As it stands, i can get this information using batch files, but i'm looking to move away from them as much as possible. I can get the information from my machine strickly using vb, but i can't figure out how to get the information from a remote machine on the same network.

Thanks
0
mcmoser
Asked:
mcmoser
  • 3
  • 2
  • 2
  • +1
1 Solution
 
JackOfPHCommented:
ping
0
 
ComputronCommented:
0
 
JackOfPHCommented:
Put this on the command button.

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 "Printer: " & dev.Name & " " & dev.Location & 
Next
devlist = Nothing

******************************
here is some article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp

0
Industry Leaders: 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!

 
mcmoserAuthor Commented:
Computron, i'm gonna have a look at that tomorrow when i go into work. I'll let you know how it went.

JackOfPH, I don't follow what you mean by ping? I know what ping does, but unless i'm mistaken, I don't think it will give me any information on printers?

Appreciate the quick responses!
0
 
ComputronCommented:
The URL I gave was not very specific, here it is
http://vbnet.mvps.org/code/network/connecttoprinterdlg.htm
0
 
DeadlyTrevCommented:
JackOfPh's solution is correct, but only works for local printers.  Try this for remote printers.

    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.Name
    Next
    Set PrinterList = Nothing
    Set WMIService = Nothing

0
 
mcmoserAuthor Commented:
DeadlyTrev,

I tried what you suggested and it's working. Is it possible to set a username & password as well into the command?
0
 
mcmoserAuthor Commented:
Think i got it working now.

    Set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objLocator.ConnectServer(RemoteComputer, "root\cimv2", RemoteUsername,   RemotePassword)
    objWMIService.Security_.impersonationlevel = 3
    Set PrinterList = objWMIService.ExecQuery("Select * from Win32_Printer")
    For Each PrinterInstance In PrinterList
        MsgBox PrinterInstance.Name
    Next
    Set PrinterList = Nothing
    Set WMIService = Nothing

Excellent, thanks a lot for all your help.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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