Procedura: enumerare un sottoinsieme di code di stampaHow to: Enumerate a Subset of Print Queues

Una situazione comune riscontrata da professionisti IT (IT) la gestione di un set a livello aziendale di stampanti consiste nel generare un elenco delle stampanti con determinate caratteristiche.A common situation faced by information technology (IT) professionals managing a company-wide set of printers is to generate a list of printers having certain characteristics. Questa funzionalità viene fornita per il GetPrintQueues metodo di un PrintServer oggetto e EnumeratedPrintQueueTypes enumerazione.This functionality is provided by the GetPrintQueues method of a PrintServer object and the EnumeratedPrintQueueTypes enumeration.

EsempioExample

Nell'esempio seguente, il codice inizia creando una matrice di flag che specificano le caratteristiche delle code di stampa che si desidera elencare.In the example below, the code begins by creating an array of flags that specify the characteristics of the print queues we want to list. In questo esempio, si sta cercando le code di stampa vengono installate localmente nel server di stampa e condivise.In this example, we are looking for print queues that are installed locally on the print server and are shared. Il EnumeratedPrintQueueTypes enumerazione offre molte altre possibilità.The EnumeratedPrintQueueTypes enumeration provides many other possibilities.

Il codice crea quindi un LocalPrintServer dell'oggetto, una classe derivata da PrintServer.The code then creates a LocalPrintServer object, a class derived from PrintServer. Server di stampa locale è il computer in cui è in esecuzione l'applicazione.The local print server is the computer on which the application is running.

L'ultimo passaggio significativo consiste nel passare la matrice di GetPrintQueues metodo.The last significant step is to pass the array to the GetPrintQueues method.

Infine, i risultati vengono presentati all'utente.Finally, the results are presented to the user.

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

È possibile estendere questo esempio con il foreach ciclo che scorre ogni coda di stampa ulteriormente screening.You could extend this example by having the foreach loop that steps through each print queue do further screening. Ad esempio, è possibile escludere le stampanti che non supportano la stampa fronte retro con la chiamata di ciclo ogni coda di stampa GetPrintCapabilities metodo e il valore restituito di test per la presenza di stampa fronte retro.For example, you could screen out printers that do not support two-sided printing by having the loop call each print queue's GetPrintCapabilities method and test the returned value for the presence of duplexing.

Vedere ancheSee Also

GetPrintQueues
PrintServer
LocalPrintServer
EnumeratedPrintQueueTypes
PrintQueue
GetPrintCapabilities
Documenti in WPFDocuments in WPF
Panoramica della stampaPrinting Overview
Microsoft XPS Document WriterMicrosoft XPS Document Writer