방법: 인쇄 큐의 하위 집합 열거

회사 차원의 프린터 집합을 관리하는 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
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 메서드를 호출하고 반환된 값이 이중화되었는지 테스트하여 양면 인쇄를 지원하지 않는 프린터를 차단할 수 있습니다.

참고 항목