Pregunta

I am enumerating printers connected in the PC. I done it using C# System.Printing namespace. It works well. But mostly it shows software printers like Microsoft XPS Document writer,Microsoft Fax etc. I would like to know is it possible to remove these ssoftware printers from enumeration. The code I have done is show below :

PrintQueue printQueue = null;

LocalPrintServer localPrintServer = new LocalPrintServer();

// Retrieving collection of local printer on user machine
PrintQueueCollection localPrinterCollection =
    localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,
                                            EnumeratedPrintQueueTypes.Connections });

System.Collections.IEnumerator localPrinterEnumerator =
    localPrinterCollection.GetEnumerator();

while (localPrinterEnumerator.MoveNext())
{
    // Get PrintQueue from first available printer
    printQueue = (PrintQueue)localPrinterEnumerator.Current;

    if (!printQueue.IsOffline)
    {
        MessageBox.Show(printQueue.FullName.ToString());
        string s = "Printer found " + printQueue.FullName.ToString();
        listBox1.Items.Add(s);
    }
    else
    {
        // No printer exist, return null PrintTicket 
        // return null;
    }
}
¿Fue útil?

Solución 2

The only way I found is to compare the name of desired printer with the one we are getting.

Otros consejos

The key to distinguishing a real printer from a virtual printer is the port the printer is using. Real printers use hardware ports such as LPT1: or USB ports. Virtual printers use software-driven ports.

The complication will be network printers. It won't be easy determining if a network printer is using a hardware port.

I know this isn't a great answer but you've posed a very difficult question. I hope it gets your started in the right direction.

Few observations:

  1. In the Properties window the Device Settings Page is available ONLY for the Real Printers and NOT for the Virtual Printers. And most of these values are available in printQueue.UserPrintTicket property

  2. printQueue.QueuePort.Name contains an IP address appended with or without the port name. ex: "20.120.12.22_1" or "20.120.12.22" for Real Printers

enter image description here

You can use the Print Spooler API to manage printers and printjobs. Specially the EnumPrinters function might be useful for you. You can grab the c# wrapper from Pinvoke.net

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top