会社全体のプリンターセットを管理する情報技術 (IT) の専門家が直面する一般的な状況は、特定の特性を持つプリンターの一覧を生成する場合です。 この機能は、GetPrintQueues オブジェクトと PrintServer 列挙体の EnumeratedPrintQueueTypes メソッドによって提供されます。
例
次の例では、リストする印刷キューの特性を指定するフラグの配列を作成することから始めます。 この例では、プリント サーバーにローカルにインストールされ、共有される印刷キューを探しています。 EnumeratedPrintQueueTypes 列挙は、他にも多くの可能性を提供します。
次に、LocalPrintServer オブジェクト (PrintServerから派生したクラス) を作成します。 ローカル プリント サーバーは、アプリケーションが実行されているコンピューターです。
最後の重要な手順は、配列を GetPrintQueues メソッドに渡すことです。
最後に、結果がユーザーに表示されます。
// 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();
// 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
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()
この例を拡張する際には、各印刷キューを順に処理する foreach
ループを使用して、さらに詳しいスクリーニングを行うことができます。 たとえば、両面印刷をサポートしていないプリンターをスクリーン アウトする場合は、ループで各印刷キューの GetPrintCapabilities メソッドを呼び出し、双方向印刷が存在する場合に戻り値をテストします。
こちらも参照ください
.NET Desktop feedback