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.
+1
A:
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
2010-01-26 18:56:17
+3
A:
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
2010-01-26 18:56:34