方法 : 印刷キューのサブセットを列挙する

企業全体のプリンターを管理する情報テクノロジ (IT) 専門家は、特定の特性を持つプリンターのリストを生成しなければならない状況に直面することがしばしばあります。 この機能は、PrintServer オブジェクトの GetPrintQueues メソッドと、EnumeratedPrintQueueTypes 列挙体によって提供されます。

使用例

次の例のコードでは、まず最初に、リストする印刷キューの特性を指定するフラグの配列を作成しています。 この例では、プリント サーバーにローカルにインストールされ、共有されている印刷キューを検索しています。 EnumeratedPrintQueueTypes 列挙体には、他にもさまざまな使用方法があります。

次にこのコードでは、PrintServer の派生クラスである LocalPrintServer オブジェクトを作成しています。 ローカル プリント サーバーは、このアプリケーションを実行中のコンピューターです。

最後の重要な手順は、配列を GetPrintQueues メソッドに渡すことです。

最後に、結果をユーザーに表示します。

            ' Specify that the list will contain only the print queues that are installed as local and are shared
            Dim enumerationFlags() As EnumeratedPrintQueueTypes = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Shared}

            Dim printServer As New LocalPrintServer()

            'Use the enumerationFlags to filter out unwanted print queues
            Dim printQueuesOnLocalServer As PrintQueueCollection = printServer.GetPrintQueues(enumerationFlags)

            Console.WriteLine("These are your shared, local print queues:" & vbLf & vbLf)

            For Each printer As PrintQueue In printQueuesOnLocalServer
                Console.WriteLine(vbTab & "The shared printer " & printer.Name & " is located at " & printer.Location & vbLf)
            Next printer
            Console.WriteLine("Press enter to continue.")
            Console.ReadLine()
// Specify that the list will contain only the print queues that are installed as local and are shared
EnumeratedPrintQueueTypes[] enumerationFlags = {EnumeratedPrintQueueTypes.Local,
                                                EnumeratedPrintQueueTypes.Shared};

LocalPrintServer printServer = new LocalPrintServer();

//Use the enumerationFlags to filter out unwanted print queues
PrintQueueCollection printQueuesOnLocalServer = printServer.GetPrintQueues(enumerationFlags);

Console.WriteLine("These are your shared, local print queues:\n\n");

foreach (PrintQueue printer in printQueuesOnLocalServer)
{
    Console.WriteLine("\tThe shared printer " + printer.Name + " is located at " + printer.Location + "\n");
}
Console.WriteLine("Press enter to continue.");
Console.ReadLine();
// Specify that the list will contain only the print queues that are installed as local and are shared
array<System::Printing::EnumeratedPrintQueueTypes>^ enumerationFlags = {EnumeratedPrintQueueTypes::Local,EnumeratedPrintQueueTypes::Shared};

LocalPrintServer^ printServer = gcnew LocalPrintServer();

//Use the enumerationFlags to filter out unwanted print queues
PrintQueueCollection^ printQueuesOnLocalServer = printServer->GetPrintQueues(enumerationFlags);

Console::WriteLine("These are your shared, local print queues:\n\n");

for each (PrintQueue^ printer in printQueuesOnLocalServer)
{
   Console::WriteLine("\tThe shared printer " + printer->Name + " is located at " + printer->Location + "\n");
}
Console::WriteLine("Press enter to continue.");
Console::ReadLine();

この例は、各印刷キューをステップ スルーしてさらに絞り込む foreach ループを追加することにより拡張できます。 たとえば、このループで各印刷キューの GetPrintCapabilities メソッドを呼び出し、戻り値を検査して両面印刷のサポートの有無を調べることで、両面印刷をサポートしないプリンターを除外することができます。

参照

参照

GetPrintQueues

PrintServer

LocalPrintServer

EnumeratedPrintQueueTypes

PrintQueue

GetPrintCapabilities

概念

WPF のドキュメント

印刷の概要

その他の技術情報

Microsoft XPS Document Writer (Microsoft XPS ドキュメント ライター)