public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
public Image GetSystemIcon(string path) {//FIXME: set and use last mod date of file to invalidate cache. if (_iconCache.ContainsKey(path)) { return _iconCache[path]; } try { SHFILEINFO shFileInfo = new SHFILEINFO(); IntPtr iconPtr = Win32.SHGetFileInfo(path, 0, ref shFileInfo, (uint)Marshal.SizeOf(shFileInfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); _iconCache.Add(path, Icon.FromHandle(shFileInfo.hIcon).ToBitmap()); } catch (Exception e) { } //if we still have no icon here for some reason, return one if (!_iconCache.ContainsKey(path)) _iconCache.Add(path, new System.Drawing.Bitmap(8, 8)); return _iconCache[path]; }