title: Why do I get the wrong SpecialFolder icon when using SHFileInfo?
body: <p>I am using <code>SHFileInfo</code> to retrieve system icons for both files and folders, however am finding that special folders do not return the correct folder icon.</p>
  
  <p>For example, the Desktop folder will return the same folder icon as a regular folder instead of the Desktop icon, and the MyComputer icon looks like an old Windows 98 icons instead of the Windows 7 MyComputer icon that I expected.</p>
  
  <p>Why am I getting the wrong icon for special folders, and how can I retrieve the correct system icon for special folders using <code>SHFileInfo</code>?</p>
  
  <p>My original code came from <a href="http://www.codeproject.com/Articles/2532/Obtaining-and-managing-file-and-folder-icons-using" rel="nofollow noreferrer">this codeproject article</a>, however it's been modified a bit. The actual code getting executed is still fairly similar though, and looks like this:</p>
  
  <pre><code>public static System.Drawing.Icon GetFolderIcon(string folderPath, IconSize size, FolderType folderType)
  {
      try
      {
          // Need to add size check, although errors generated at present!
          Int64 flags = WinApi.SHGFI_ICON | WinApi.SHGFI_USEFILEATTRIBUTES;
  
          if (FolderType.Open == folderType)
              flags |= WinApi.SHGFI_OPENICON;
  
          if (IconSize.Small == size)
              flags |= WinApi.SHGFI_SMALLICON;
          else
              flags |= WinApi.SHGFI_LARGEICON;
  
          // Get the folder icon
          WinApi.SHFILEINFO shfi = new WinApi.SHFILEINFO();
          WinApi.SHGetFileInfo(folderPath,
              WinApi.FILE_ATTRIBUTE_DIRECTORY,
              ref shfi,
              (Int32)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
              flags);
  
          if (shfi.hIcon == IntPtr.Zero)
              return null;
  
          // Now clone the icon, so that it can be successfully stored in an ImageList
          System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone();
  
          WinApi.DestroyIcon(shfi.hIcon);     // Cleanup
          return icon;
      }
      catch (Exception ex)
      {
          // Log Error
      }
  
      return null;
  }
  </code></pre>
  
  <p>With the call to it looking like this:</p>
  
  <pre><code>var icon = IconUtil.GetFolderIcon(
      Environment.GetFolderPath(Environment.SpecialFolder.Desktop), 
      IconUtil.IconSize.Large, IconUtil.FolderType.Closed);
  </code></pre>
  
  <p>I get icons that look like this</p>
  
  <p><img src="https://i.stack.imgur.com/UbPKU.png" alt="enter image description here"></p>
  
  <p>instead of this</p>
  
  <p><img src="https://i.stack.imgur.com/fHJ7i.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/EvW9x.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/AMP2b.png" alt="enter image description here"></p>