How can I get an executable icon in .Net?

I am looking to get an executable application icon in .Net. How can i do this? I think I will have to request its resources, some of them, but I am open to any general type of solution.

+4
source share
2 answers

From the hard way:

Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filePath); 

From dll resource:

 // 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:

C # Retrieving system icons and icons

+3
source

The following should work. It also pulls out an icon for other types of files (i.e. a white piece of paper for .txt), although it will not pull out inline thumbnails (since they are introduced by shell extensions).

icon = Icon.ExtractAssociatedIcon(filename);

+1
source

Source: https://habr.com/ru/post/1299464/


All Articles