1

問題

リモート サーバーで使用可能な印刷キューのリストを取得しようとしています。

最終的には 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 つはリモート接続)
    • Lプリンター1
    • LPrinter2
    • \\remote\RPrinter1
  • \\remote ( 2 つの印刷キューが定義されたリモート コンピュータ)
    • Rプリンター1
    • RPrinter2
  • \\other ( 1 つの印刷キューが定義されている他のコンピューター)
    • Oプリンター

結果は次のとおりです。

プリント サーバー=\\local  
\\local\LPrinter1  
\\local\LPrinter2  
\\remote\RPrinter1  

プリント サーバー=\\リモート  
\\remote\RPrinter1  

プリント サーバー=\\その他
\\remote\RPrinter1  

ネットワーク上の有効なコンピューターである限り、プリント サーバー名が何であれ問題ではないため、GetPrintQueues() メソッド内で何かが発生して、プリント サーバーがローカル ボックスにリセットされていると推測されます。

4

2 に答える 2

1

答えを見つけた...それが私が望んでいたものでなくても。

列挙フラグをローカルのみに変更し、過去にログオンしたサーバーに接続すると、正しいプリンターが取得されますしかし、ログオンしていない場合は、自分のマシンからリモート プリント キューのリストを取得します。

WMI を使用して同様の操作を試みると、接続先のリモート サーバーで Access Denied エラーが発生します。私の推測では、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
于 2010-10-27T20:19:25.753 に答える
0
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
于 2016-06-09T16:16:35.947 に答える