2

Possible Duplicate:
Can I get the icon associated with an installed printer through .Net?

How do I retrieve icons associated with printers with C#.NET? I would ideally like to have icons shown in "Printers and Devices" folder for printers to be used in my application.

One way is to hard-code the path to the folders with installed printers and retrieve the icons manually one after another. This question was already asked here.

However, this approach relies on scanning a given folder, get the associated printers, match the printer names with the ones that were retrieved and display them.

This approach can be flaky for two reasons:

  1. This involves hard-coding the location to the printers (which can vary by OS/version)

  2. There is no guarantee that the printer names displayed will match up with the printer names already enlisted with the application.

Is there a programmatic/managed approach which does not involve scanning/manual approach, but icon could be retrieved as property of some managed .NET object ?

Community
  • 1
  • 1
Vishnu Pedireddi
  • 2,142
  • 4
  • 25
  • 34
  • The answer was conclusive. Windows checks the installed drivers and searche throug until it finds the icon. – Cole Tobin Sep 01 '12 at 00:45
  • Can I ask what you are going to use them for and [what have you tried](http://www.whathaveyoutried.com) – Cole Tobin Sep 01 '12 at 00:48
  • The marked answer shows a way to retrieve icons from a given *.dll or *.exe. However, which dll's or exe's should I retrieve it from ? – Vishnu Pedireddi Sep 01 '12 at 00:49
  • The application features a custom print dialog, for which I list the available printers. Having printer icons as quick visual aid is helpful. And no I am searching for an direction to retrieve icons. – Vishnu Pedireddi Sep 01 '12 at 00:50
  • Look through the registry. Find something that looks like it lists installed printers. Find the thing that references what dll the icon is in. Load it. The answer was complete. The location depends on the publishers mind – Cole Tobin Sep 01 '12 at 00:52
  • My question is very specific to use .NET framework to perform such an action. If I were to get into the business of searching registry's, I would be using the old-fashioned COM object model. The whole point is to leverage what .NET has to offer. – Vishnu Pedireddi Sep 01 '12 at 00:56
  • Not scan using your application. Scan yourself and have your app scan the tree it is underneath. – Cole Tobin Sep 01 '12 at 00:58
  • @ColeJohnson Please read the updated question. – Vishnu Pedireddi Sep 01 '12 at 01:10
  • Whats wrong with the second solution in that thread: http://stackoverflow.com/questions/1063874/retrieving-icons-of-current-user-printers – Jeremy Thompson Sep 01 '12 at 01:44
  • 1
    The first solution on that sounds like it works. I can convert it to C# if you need. – Cole Tobin Sep 01 '12 at 05:34

1 Answers1

2

Using KnownFolders you might be able to get the icons of all installed printers and their paths.

There is this FOLDERID_PrintersFolder with GUID {76FC4E2D-D6AD-4519-A663-37BD56068185}, which is Devices and Printers folder.

For C# you have classes to access them in Windows® API Code Pack for Microsoft® .NET Framework.

Now to get the icon, you create a shortcut of this Control Panel item, look at it with Notepad, inside there will be the path to the icon. In my case it was'C:\Users\xxx\appdata\Local\Microsoft\Device Metadata\dmrccache\en-US\4a65bbe0-2f89-48c1-b84c-8ffdf878dc43\DeviceInformation\thinkpad.ico'.

Use Shell Links or Creating application shortcut in a directory to create shortcuts

Community
  • 1
  • 1
aybe
  • 15,516
  • 9
  • 57
  • 105