The only way I found is to compare the name of desired printer with the one we are getting.
سؤال
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;
}
}
المحلول 2
نصائح أخرى
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:
In the
Properties
window theDevice Settings
Page is available ONLY for the Real Printers and NOT for the Virtual Printers. And most of these values are available inprintQueue.UserPrintTicket
propertyprintQueue.QueuePort.Name
contains anIP
address appended with or without the port name. ex: "20.120.12.22_1" or "20.120.12.22" for Real Printers
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