Link to home
Create AccountLog in
Avatar of mcmoser
mcmoser

asked on

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
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

ping
Avatar of Computron
Computron

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

Avatar of mcmoser

ASKER

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

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of mcmoser

ASKER

DeadlyTrev,

I tried what you suggested and it's working. Is it possible to set a username & password as well into the command?
Avatar of mcmoser

ASKER

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.