Problem
I'm trying to get a list of print queues available on a remote server.
Ultimately this will need to be performed from ASP.NET, but for now I'd settle for a console application to work.
When I create an instance of the System.Printing.PrintServer class using the path to a remote server I am able to get basic information about the Print Server. But when I call the GetPrintQueues method I only get queues that are defined on the local box. No matter what I use for the remote device.
Code
Imports System.Printing
Module Module1
Sub Main()
ListPrintQueues("\\local")
ListPrintQueues("\\remote")
ListPrintQueues("\\other")
End Sub
Sub ListPrintQueues(ByVal server As String)
Dim ps As New PrintServer(server)
Console.WriteLine("Printer Server=" & ps.Name)
Dim flags() As EnumeratedPrintQueueTypes = {EnumeratedPrintQueueTypes.Connections, EnumeratedPrintQueueTypes.Local}
Dim queues As PrintQueueCollection = ps.GetPrintQueues(flags)
For Each pq As PrintQueue In queues
Console.WriteLine(pq.FullName)
Next
Console.WriteLine()
End Sub
End Module
Example:
Assuming the following configuration
- \\local (Local computer with 3 print queues defined, 1 is a remote connection)
- LPrinter1
- LPrinter2
- \\remote\RPrinter1
- \\remote (Remote computer with 2 print queues defined)
- RPrinter1
- RPrinter2
- \\other (Some other computer with 1 print queue defined)
- OPrinter
The results are:
Print Server=\\local \\local\LPrinter1 \\local\LPrinter2 \\remote\RPrinter1 Print Server=\\remote \\remote\RPrinter1 Print Server=\\other \\remote\RPrinter1
My best guess is that something is happening inside the GetPrintQueues() method to cause the print server to be reset to the local box since it doesn't matter what the print server name is as long as it's a valid computer on the network.