如何让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 结果是: 打印服务器= \ local \当地 LPrinter1 \当地 LPrinter2 \远程 RPrinter1 打印服务器= \远程 \远程 RPrinter1 打印服务器= \ other \远程 RPrinter1 我最好的猜测是,在GetPrintQueues()方法中发生了一些事情,导致打印服务器被重置为本地盒,因为只要它是网络上的有效计算机,打印服务器名称无关紧要。     
已邀请:
发现了一个答案......即使它不是我想要的。 如果我将枚举标志更改为仅本地并连接到我以前登录过的服务器,我将获得正确的打印机。但如果我还没有登录,那么我会从我的机器上获取远程打印队列列表。 当我尝试使用WMI执行类似操作时,我在连接到的远程服务器上出现“拒绝访问”错误。我的猜测是System.Printing正在捕获异常然后默认为本地打印服务器。 改变了代码
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
    
Private Sub btnreanudar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreanudar.Click
    Dim SERVIDOR As New System.Printing.PrintServer() 'SUPERIOR DEL SISTEMA DE IMPRESION (EL ORDENADOR)
    Dim IMPRESORAS As PrintQueueCollection = SERVIDOR.GetPrintQueues() 'IMPRESORAS DISPONIBLES
    For Each IMPRESORA As PrintQueue In IMPRESORAS 'RECORRE TODAS LAS IMPRESORAS
        Try
            If IMPRESORA.NumberOfJobs > 0 Then 'SI LA IMPRESORA TIENE ALGUNA IMPRESION EN MARCHA......
                IMPRESORA.Refresh()
                Dim IMPRESIONES As PrintJobInfoCollection = IMPRESORA.GetPrintJobInfoCollection() 'CREA UNA COLECCION DE IMPRESIONES EN MARCHA
                For Each IMPRESION In IMPRESIONES ' POR CADA IMPRESION......
                    If IMPRESION.JobIdentifier = joblist.CurrentRow.Cells("JobId").Value Then
                        IMPRESION.Resume()
                        Exit Sub
                    End If
                Next
            End If
        Catch ex As Exception
        End Try
    Next
End Sub
    

要回复问题请先登录注册