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
mcmoserAsked:
Who is Participating?
 
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
 
JackOfPHCommented:
ping
0
 
ComputronCommented:
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.