[ACCEPTED]-How can I get the icon from the executable file only having an instance of it's Process in C#-c#
Accepted answer
Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);
0
This is a sample from a console application 1 implementation.
using System;
using System.Drawing; //For Icon
using System.Reflection; //For Assembly
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
try
{
//Gets the icon associated with the currently executing assembly
//(or pass a different file path and name for a different executable)
Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
}
catch(ArgumentException ae)
{
//handle
}
}
}
}
Use the ExtractIconEx (and here) p/invoke. You can extract 7 small and large icons from any dll or exe. Shell32.dll 6 itself has over 200 icons that are quite 5 useful for a standard Windows application. You 4 just have to first figure out what the index 3 is for the icon(s) you want.
Edit: I did 2 quick SO search and found this. The index 0 1 icon is the application icon.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.