Поделиться через


Практическое руководство. Перечисление подмножества очередей печати

Обычной ситуацией, возникающей у специалистов по информационным технологиям, управляющих множеством принтеров компании, является получение списка принтеров, имеющих определенные характеристики. Эта функциональная возможность обеспечивается методом 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
            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