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?

[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.

JackOfPHCommented:
ping
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

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!

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!
ComputronCommented:
The URL I gave was not very specific, here it is
http://vbnet.mvps.org/code/network/connecttoprinterdlg.htm
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

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
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?
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.
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.