public static Icon GetIcon(string path, ItemType type)
        {
            var attributes = (uint)(type == ItemType.Folder ? FileAttribute.Directory : FileAttribute.File);

            var flags = (uint)(ShellAttribute.Icon | ShellAttribute.UseFileAttributes);

            flags = flags | (uint)ShellAttribute.SmallIcon;

            var fileInfo = new ShellFileInfo();
            var size     = (uint)Marshal.SizeOf(fileInfo);
            var result   = Interop.SHGetFileInfo(path, attributes, out fileInfo, size, flags);

            if (result == IntPtr.Zero)
            {
                return(null);
            }
            try
            {
                return((Icon)Icon.FromHandle(fileInfo.hIcon).Clone());
            }
            catch
            {
                return(null);
            }
            finally
            {
                Interop.DestroyIcon(fileInfo.hIcon);
            }
        }
 public static extern IntPtr SHGetFileInfo(string path,
                                           uint attributes,
                                           out ShellFileInfo fileInfo,
                                           uint size,
                                           uint flags);