Aracılığıyla paylaş


Nasıl yapılır: Yazdırma Kuyruklarının Alt Kümesini Numaralandırma

Şirket genelinde bir yazıcı kümesini yöneten bilgi teknolojisi (BT) uzmanlarının karşılaştığı yaygın bir durum, belirli özelliklere sahip yazıcıların listesini oluşturmaktır. Bu işlevsellik, bir PrintServer nesnenin GetPrintQueues yöntemi ve numaralandırması EnumeratedPrintQueueTypes tarafından sağlanır.

Örnek

Aşağıdaki örnekte kod, listelemek istediğimiz yazdırma kuyruklarının özelliklerini belirten bir bayrak dizisi oluşturarak başlar. Bu örnekte, yazdırma sunucusuna yerel olarak yüklenen ve paylaşılan yazdırma kuyruklarını arıyoruz. Numaralandırma EnumeratedPrintQueueTypes başka birçok olasılık sağlar.

Kod daha sonra öğesinden PrintServertüretilen bir sınıf olan bir nesnesi oluştururLocalPrintServer. Yerel yazdırma sunucusu, uygulamanın üzerinde çalıştığı bilgisayardır.

Son önemli adım, diziyi yöntemine geçirmektir GetPrintQueues .

Son olarak, sonuçlar kullanıcıya sunulur.

// 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()

Her yazdırma kuyruğunda ilerleten döngünün foreach daha fazla tarama gerçekleştirmesini sağlayarak bu örneği genişletebilirsiniz. Örneğin, döngünün her yazdırma kuyruğunun GetPrintCapabilities yöntemini çağırmasını ve çift yönlü yazdırmanın varlığı için döndürülen değeri test etmelerini sağlayarak, çift taraflı yazdırmayı desteklemeyen yazıcıları görüntüleyebilirsiniz.

Ayrıca bkz.