如何获得System.Printing.PrintServer.GetPrintQueues返回来自远程服务器的打印队列列表?队列、如何获得、服务器、列表

由网友(时光怎么让爱笑的人哭了)分享简介:我试图获取打印队列的列表可在远程服务器上。 这最终将需要从ASP.NET进行,但现在我会满足于一个控制台应用程序的工作。的当我创建的实例在 System.Printing.PrintServer 使用路径到远程服务器,我能够获得有关打印服务器的基本信息类。但是,当我致电 GetPrintQueues方法,我只能得到那...

我试图获取打印队列的列表可在远程服务器上。

这最终将需要从ASP.NET进行,但现在我会满足于一个控制台应用程序的工作。的

当我创建的实例在 System.Printing.PrintServer 使用路径到远程服务器,我能够获得有关打印服务器的基本信息类。但是,当我致电 GetPrintQueues方法,我只能得到那些对当地中定义队列。不管我用什么远程设备。

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.

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

地方(的与定义3打印队列本地计算机,1是一个远程连接的) LPrinter1 LPrinter2 远程 RPrinter1 local (Local computer with 3 print queues defined, 1 is a remote connection) LPrinter1 LPrinter2 remoteRPrinter1 RPrinter1 RPrinter2 OPrinter

的结果是:


Print Server=local  
localLPrinter1  
localLPrinter2  
remoteRPrinter1  

Print Server=remote  
remoteRPrinter1  

Print Server=other
remoteRPrinter1  

我最好的猜测是,事情正在发生的GetPrintQueues内()方法来使打印服务器复位到本地主机,因为它没关系打印服务器的名称是什么,只要它是一个有效的计算机上网络上。

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.

推荐答案

发现了一个答案......即使这不是我想要的。

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.

当我尝试使用WMI我得到拒绝访问,我已经连接到远程服务器上的错误类似的行动。我的猜测是,System.Printing被捕捉异常则默认为本地打印服务器。

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.

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.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
阅读全文

相关推荐

最新文章