C# – How Do I Extract a Full Icon From a Vista/7 Executable

cextractioniconsnetwindows-vista

If I have a Vista .ico file which contains a 16×16, 32×32, 256×256 etc. version of an icon, I can successfully load it as a .NET Icon by simply doing -:

Icon myIcon = new Icon("C:\\MyIcon.ico");

I can then access all of the various sized images in the icon. I can even access the 256×256 Vista PNG using methods detailed HERE.

However, I haven't found a way to get the full set of icon images from a Vista executable. Unfortunately, doing this -:

Icon myIcon = Icon.ExtractAssociatedIcon("C:\\MyExe.exe");

…only results in a single 32×32 image being extracted. Is there a way get the entire set of images from an executable as a .NET Icon? Preferably one that also works in XP.

Best Answer

Have a look at this article 'IconLib' on CodeProject. Also, look at this version using the 'ExtractIconExA' API via pinvoke in VB.NET.

Hope this helps.