如何让 System.Printing.PrintServer.GetPrintQueues 从远程服务器返回打印队列列表?
问题
我正在尝试获取远程服务器上可用的打印队列列表。
最终这需要从 ASP.NET 执行,但现在我愿意让控制台应用程序工作。
当我创建 System.Printing.PrintServer 的实例使用远程服务器路径的强> 类我能够获取有关打印服务器的基本信息。但是,当我调用 GetPrintQueues 方法时,我只能获取在本地框上定义的队列。无论我使用什么远程设备。
代码
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
示例:
假设以下配置
- \\local(定义了 3 个打印队列的本地计算机,1 个是远程连接)
- LPrinter1
- LPrinter2
- \\远程\RPrinter1
- \\remote(定义了 2 个打印队列的远程计算机)
- RPrinter1
- RPrinter2
- \\other(定义了 1 个打印队列的其他计算机)
- OPrinter
结果是:
Print Server=\\local \\local\LPrinter1 \\local\LPrinter2 \\remote\RPrinter1 Print Server=\\remote \\remote\RPrinter1 Print Server=\\other \\remote\RPrinter1
我最好的猜测是 GetPrintQueues() 方法内部发生了一些事情,导致打印服务器重置为本地框,因为打印服务器名称是什么并不重要,只要它是网络上的一台有效计算机。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了答案......即使这不是我想要的。
如果我将枚举标志更改为仅本地并连接到我过去登录过的服务器,我将获得正确的打印机。但如果我还没有登录,那么我会从我的机器获取远程打印队列列表。
当我尝试使用 WMI 执行类似操作时,我在已连接的远程服务器上收到“访问被拒绝”错误。我的猜测是 System.Printing 捕获异常然后默认为本地打印服务器。
更改了代码
Discovered an answer...even if it's not what I wanted.
If I change the enumeration flags to local only and connect to a server that I have logged on to in the past I will get the correct printers. But if I have not logged on then I get list of remote print queues from my machine.
When I attempt similar actions using WMI I get Access Denied errors on the remote server that I've connected to. My guess is that System.Printing is catching the exception then defaulting to the local print server.
changed code