none
physical device printer OR document writer printer?? RRS feed

  • Question

  • Hi,

    I've been searching answer to this, but I could not find anything.

    I would like to know if the selected printer on the Print Dialog is an actual printer device or is it a document writer such as PDF or XPS writer.

    I feel this is a basic property, but I am wondering why .NET does not have this API.

    Kindly help me.

     

    Thanks in advance.  :)

    Wednesday, March 16, 2011 7:20 AM

Answers

  • The list of all available printers is easy to get, as you know in these printers, some are virtual and some are physical.
    Yeah trying to exhauste all the virtual printers and remove them from the list is not advisable as the names of the printers can be changed.
    We could use some special properties to distinguish them. Here I used WMI to get the list of the properties of all the printers available.
    See it with the following code first:

     String wmiSQL = "SELECT * FROM Win32_Printer";
     ManagementObjectCollection printers = new ManagementObjectSearcher(wmiSQL).Get();
    
     foreach (ManagementObject printer in printers)
     {
     	PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator();
    
     	while (pde.MoveNext())
     	{
     		//if (pde.Current.Name == "Name" || pde.Current.Name == "Published")
     		Console.WriteLine(pde.Current.Name + " : " + pde.Current.Value);
     	}
     	Console.WriteLine("===============================One Printer End===============================" + Environment.NewLine);
     }
    
    



    I’ve find that all the virtual printers are not published, the “Published” properties of them are all set to false. You can enable the commented line in the above code to check it out.
    Go on researching all these properties, you may find some other properties to achieve. One deserted property is “PrintProcessor”, as here in my environment, this kind of properties to all the virtual printers involve string “winprint” or “ModiPrint” but physical printers doesn’t. While this is not true in some other guys’ environment.


    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no
    Wednesday, March 30, 2011 6:58 AM
    Moderator

All replies

  • Check out registry keys in HKEY_CURRENT_USER\Printers

    It seems to contain physical printers only.


    Tan Silliksaar milemarx.com
    Wednesday, March 16, 2011 7:37 AM
  • Hi Tan,

    Thanks for the response.

    But I checked HKEY_CURRENT_USER\Printers folder in the registry, and in my case it contains the Microsoft XPS Document Writer.

     

    Wednesday, March 16, 2011 7:47 AM
  • There's a lot of printer information in the registry.

    One way to find it is to search for known printer names and compare the differences between the physical ones and virtual ones.


    Tan Silliksaar milemarx.com
    Wednesday, March 16, 2011 7:55 AM
  • Thanks for that suggestion.

    But that method would not be very wise, I think. I do not want to compare each and every new printers introduced in the market, into my registry of existing printers.

    I am looking of a more "standard" way of doing it..

    Thursday, March 24, 2011 1:03 AM
  • You can use the PrinterSettings.InstalledPrinters Property under the System.Drawing.Printing namespace to gets the names of all printers installed on the computer.

     foreach (String pkInstalledPrinters in PrinterSettings.InstalledPrinters)
      Console.WriteLine(pkInstalledPrinters);
    

    For the items you don’t want, like Microsoft XPS Document Writer, you should write code to filter them by your own.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 25, 2011 2:54 AM
    Moderator
  • Hello Leo,

     

    Thanks for the response. I appreciate it.

    You got the part of getting the list of available printers correct.

     

    However, that is not the problem. The problem is -- which among the list of printers are actual device printers and which are not (example, document writer printers such as XPS writer or PDF writers). What I want to do in my program is that, if selected printer in Print Dialog is actual device, perform MethodA, if a document writer printer is selected, perform MethodB.

     

    It is not possible that the programmer will create his own list and just compare it to the list of available printers you've just mentioned. My WORRY is that, what if the user installed another PDF writer, and that printer was not on my list, then that would be wrong. And then, I also do not want to use string filters such as checking if there are substrings "XPS" or "PDF" on the printer name, because users can easily change the printer name.

     

    I hope you understand the actual problem. What I am looking for is solution that is more robust and flexible.

     

    Thanks in advance.  :)

    Monday, March 28, 2011 1:53 AM
  • The list of all available printers is easy to get, as you know in these printers, some are virtual and some are physical.
    Yeah trying to exhauste all the virtual printers and remove them from the list is not advisable as the names of the printers can be changed.
    We could use some special properties to distinguish them. Here I used WMI to get the list of the properties of all the printers available.
    See it with the following code first:

     String wmiSQL = "SELECT * FROM Win32_Printer";
     ManagementObjectCollection printers = new ManagementObjectSearcher(wmiSQL).Get();
    
     foreach (ManagementObject printer in printers)
     {
     	PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator();
    
     	while (pde.MoveNext())
     	{
     		//if (pde.Current.Name == "Name" || pde.Current.Name == "Published")
     		Console.WriteLine(pde.Current.Name + " : " + pde.Current.Value);
     	}
     	Console.WriteLine("===============================One Printer End===============================" + Environment.NewLine);
     }
    
    



    I’ve find that all the virtual printers are not published, the “Published” properties of them are all set to false. You can enable the commented line in the above code to check it out.
    Go on researching all these properties, you may find some other properties to achieve. One deserted property is “PrintProcessor”, as here in my environment, this kind of properties to all the virtual printers involve string “winprint” or “ModiPrint” but physical printers doesn’t. While this is not true in some other guys’ environment.


    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no
    Wednesday, March 30, 2011 6:58 AM
    Moderator
  • Hello Leo!

     

    That information seems very helpful!!!

    I think this would be able to solve my problem.

    Thank you very much!

     

    Monday, April 4, 2011 12:49 AM
  • Glad to hear that the info are helpful.
    Wish you a wonderful week!
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 4, 2011 3:45 AM
    Moderator
  • I dont think so the solution of published Attribute will work...U can publish the virtual printer,and your physical printer may not be published necessarily,so not an valid solution...

    one solution that i hv found is change the Imageablearea of page to huge value,

    It shows different behavior for physical and virtual printer

    http://stackoverflow.com/questions/5112543/portable-way-to-determining-of-printer-is-physical-or-virtual

    Wednesday, November 13, 2013 7:12 AM