public static Bitmap GenerateThumbnail(string filename) { Bitmap result; if (Environment.OSVersion.Version.Major < 6) { result = null; } else { IShellItem shellItem = null; IntPtr zero = IntPtr.Zero; Guid riid = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe"); Bitmap bitmap = null; UnsafeNativeMethods.SHCreateItemFromParsingName(filename, IntPtr.Zero, riid, out shellItem); try { ((IShellItemImageFactory)shellItem).GetImage(new SIZE(256, 256), SIIGBF.SIIGBF_THUMBNAILONLY, out zero); bitmap = ThumbnailGenerator.ConvertPixelByPixel(zero); } catch (Exception) { try { if (shellItem != null) { Marshal.ReleaseComObject(shellItem); } if (zero != IntPtr.Zero) { Marshal.Release(zero); } } catch (Exception) { } result = null; return(result); } Marshal.ReleaseComObject(shellItem); Marshal.Release(zero); result = bitmap; } return(result); }