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


Инструкция: Перечисление подмножества очередей печати

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

См. также