Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query print server 1

Status
Not open for further replies.

gwigton

Programmer
Jul 23, 2002
52
US
I am creating a application that will list all the printers on a print server. I not only need the shared name of the printer but the comments about the printer and the IP address. This application also needs to be able to run from any client in the domain. Does anyone know how to query the printers that are on a remote print server?

Thanks in advance!!
 
>>This application also needs to be able to run from any client in the domain

What OS are the clients running?
 
If you're using Windows 2000 or better or are willing to do an additional install, then this code will do the trick for you. you will need to add the Windows Common control to your project, add a command button to the form and a listview control to your form. Then paste the following code into your form:

Code:
Option Explicit

Private Sub Command1_Click()
    Dim wmgts As Object
    Dim myPrinters As Object
    Dim APrinter As Object
    Dim li As ListItem
    Dim lstrPrintServer as String

    lstrPrintServer = "localhost"

    Set wmgts = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & lstrPrintServer)
    For Each APrinter In wmgts.instancesof("Win32_Printer")
        Set li = Me.ListView1.ListItems.Add(, , APrinter.Name)
        li.SubItems(1) = APrinter.portname
        li.SubItems(2) = APrinter.comment & vbNullString
    Next
    
End Sub

Private Sub Form_Load()
   
    Me.ListView1.ColumnHeaders.Clear
    Me.ListView1.ColumnHeaders.Add , , "Name", 3435.024
    Me.ListView1.ColumnHeaders.Add , , "Port", 3195.213
    Me.ListView1.ColumnHeaders.Add , , "Comments", 4196.764
    
    Me.ListView1.Left = 0
    
    Me.ListView1.View = lvwReport
End Sub

Private Sub Form_Resize()
    Me.ListView1.Width = Me.Width
End Sub

See for more information and properties that you can extract out about the printer.

I should also note that there may be some security issues with this and that this is untested code so it may/may not work on other operating systems as I expect it to. This was tested using "localhost" which is an XP machine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top