Flow-Launcher/Flow.Launcher · error · ShellContextMenuException
Failed to get the desktop shell folder
Error message
Failed to get the desktop shell folder
What it means
Thrown as ShellContextMenuException when SHGetDesktopFolder(out pUnkownDesktopFolder) returns anything other than S_OK on first access, meaning the Windows shell's desktop IShellFolder could not be obtained. The desktop folder is the root of the shell namespace and is required to build any context menu; without it the entire shell-context-menu feature cannot operate.
Source
Thrown at Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenu.cs:228
#endregion
#region GetDesktopFolder()
/// <summary>
/// Gets the desktop folder
/// </summary>
/// <returns>IShellFolder for desktop folder</returns>
private IShellFolder GetDesktopFolder()
{
IntPtr pUnkownDesktopFolder = IntPtr.Zero;
if (null == _oDesktopFolder)
{
// Get desktop IShellFolder
int nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);
if (S_OK != nResult)
{
throw new ShellContextMenuException("Failed to get the desktop shell folder");
}
_oDesktopFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(pUnkownDesktopFolder, typeof(IShellFolder));
}
return _oDesktopFolder;
}
#endregion
#region GetParentFolder()
/// <summary>
/// Gets the parent folder
/// </summary>
/// <param name="folderName">Folder path</param>
/// <returns>IShellFolder for the folder (relative from the desktop)</returns>
private IShellFolder GetParentFolder(string folderName)
{View on GitHub (pinned to 7fc63b07bb)
Solutions
- Run 'sfc /scannow' and 'DISM /Online /Cleanup-Image /RestoreHealth' to repair shell/system files.
- Disable recently-installed shell extensions (shell extension managers, context-menu adders) and retry to isolate a faulty one.
- Ensure the code runs in an interactive user session with Explorer running.
- Catch ShellContextMenuException at the caller and degrade to a basic menu or a Process.Start fallback.
- If persistent, create a new user profile to rule out per-profile shell corruption.
Example fix
// before
int nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);
if (S_OK != nResult)
throw new ShellContextMenuException("Failed to get the desktop shell folder");
// after — include HRESULT and free the partial pointer
int nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);
if (S_OK != nResult)
{
if (pUnkownDesktopFolder != IntPtr.Zero) Marshal.Release(pUnkownDesktopFolder);
throw new ShellContextMenuException(
$"Failed to get the desktop shell folder (HRESULT 0x{nResult:X})");
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try { var menu = new ShellContextMenu(); menu.ShowContextMenu(...); }
catch (ShellContextMenuException ex) { Log.Warn(...); // fall back to a basic menu } Prevention
- Catch ShellContextMenuException and degrade to a basic menu when the desktop folder is unavailable.
- Run 'sfc /scannow' to repair shell/system files if the desktop folder consistently fails.
- Disable recently-added shell extensions to isolate a faulty one.
- Ensure the code runs in an interactive user session with Explorer initialized.
When it happens
Trigger: The shell is in a broken state (Explorer crashed/corrupt shell registration); the call is made from a context without a valid desktop session (e.g. a service session, or before shell initialization); a shell extension registered for the desktop namespace crashed during initialization causing SHGetDesktopFolder to fail; insufficient privileges to access the shell namespace.
Common situations: Explorer/shell corruption requiring 'sfc /scannow' or a user-profile rebuild; a buggy third-party shell extension loaded into the desktop namespace failing its initialization; running the code in a non-interactive/session-0 context; severe registry corruption of shell namespace keys.
Related errors
- Failed to open folder and select item
- Failed to get IShellItemImageFactory
- Failed to get thumbnail
- Failed to parse folder path
- Failed to parse file path
AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13).
Data as JSON: /api/errors/f7d8b13590d41d17.
Report an issue: GitHub.