First of all, there are several image sizes, some of which are easier to obtain than others. If you want the “regular” size one (I believe 32x32) and can use WPF (referring to PresentationCore), this is a great way to do this:
public System.Windows.Media.ImageSource Icon
{
get
{
if (icon == null && System.IO.File.Exists(Command))
{
using (System.Drawing.Icon sysicon = System.Drawing.Icon.ExtractAssociatedIcon(Command))
{
icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
sysicon.Handle,
System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
}
return icon;
}
}
source
share