{"record":{"id":"f7d8b13590d41d17","repo":"Flow-Launcher/Flow.Launcher","slug":"failed-to-get-the-desktop-shell-folder","errorCode":null,"errorMessage":"Failed to get the desktop shell folder","messagePattern":"Failed to get the desktop shell folder","errorType":"exception","errorClass":"ShellContextMenuException","httpStatus":null,"severity":"error","filePath":"Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenu.cs","lineNumber":228,"sourceCode":"        #endregion\n\n        #region GetDesktopFolder()\n\n        /// <summary>\n        /// Gets the desktop folder\n        /// </summary>\n        /// <returns>IShellFolder for desktop folder</returns>\n        private IShellFolder GetDesktopFolder()\n        {\n            IntPtr pUnkownDesktopFolder = IntPtr.Zero;\n\n            if (null == _oDesktopFolder)\n            {\n                // Get desktop IShellFolder\n                int nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);\n                if (S_OK != nResult)\n                {\n                    throw new ShellContextMenuException(\"Failed to get the desktop shell folder\");\n                }\n                _oDesktopFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(pUnkownDesktopFolder, typeof(IShellFolder));\n            }\n\n            return _oDesktopFolder;\n        }\n\n        #endregion\n\n        #region GetParentFolder()\n\n        /// <summary>\n        /// Gets the parent folder\n        /// </summary>\n        /// <param name=\"folderName\">Folder path</param>\n        /// <returns>IShellFolder for the folder (relative from the desktop)</returns>\n        private IShellFolder GetParentFolder(string folderName)\n        {","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/Flow-Launcher/Flow.Launcher/blob/7fc63b07bbaa10a0f0b2601487913fcba9ed24b0/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenu.cs#L210-L246","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nint nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);\nif (S_OK != nResult)\n    throw new ShellContextMenuException(\"Failed to get the desktop shell folder\");\n\n// after — include HRESULT and free the partial pointer\nint nResult = SHGetDesktopFolder(out pUnkownDesktopFolder);\nif (S_OK != nResult)\n{\n    if (pUnkownDesktopFolder != IntPtr.Zero) Marshal.Release(pUnkownDesktopFolder);\n    throw new ShellContextMenuException(\n        $\"Failed to get the desktop shell folder (HRESULT 0x{nResult:X})\");\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { var menu = new ShellContextMenu(); menu.ShowContextMenu(...); }\ncatch (ShellContextMenuException ex) { Log.Warn(...); // fall back to a basic menu }","preventionTips":["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."],"tags":["shell","context-menu","com","explorer","win32"],"backgroundTag":null,"analyzedSha":"7fc63b07bbaa10a0f0b2601487913fcba9ed24b0","analyzedAt":"2026-08-13T14:54:20.914Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}