I'm looking to get an executable's application icon in .Net. How can I do this? I'm thinking I'll have to query its resources, some how, but I'm open to any general-case solution.
Asked
Active
Viewed 196 times
4
-
Is this from another application? – ChrisF Jan 26 '10 at 18:52
-
Yes. I want to retrieve the icon of an executable via its path from the app I'm writing. – Mike Pateras Jan 26 '10 at 18:53
2 Answers
3
From a hard-path:
Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
From a resource dll:
// Process handle
IntPtr processHandle = System.Diagnostics.Process.GetCurrentProcess().Handle;
// DLL path
string DLLPath = Path.Combine(Environment.SystemDirectory, "shell32.dll");
// Open folder icon index
int iconIndex = 4;
// Extract icon
System.IntPtr oPtr = ExtractIcon(processHandle, DLLPath, iconIndex);
Icon oIcon = Icon.FromHandle(oPtr);
From:

George Johnston
- 31,652
- 27
- 127
- 172
1
The following should work. It also pulls the icon for other file types (i.e. a white sheet of paper for .txt), though it will not pull embedded thumbnails (since those are injected by shell extensions).
icon = Icon.ExtractAssociatedIcon(filename);

David
- 24,700
- 8
- 63
- 83