Flow-Launcher/Flow.Launcher · warning · COMException
Failed to open folder and select item
Error message
Failed to open folder and select item
What it means
Thrown as COMException with the selection HRESULT when SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0) returns a failed HRESULT, after both the folder and file PIDLs were successfully parsed. This is the actual 'open Explorer and highlight the item' call failing at the shell level despite valid inputs.
Source
Thrown at Flow.Launcher.Infrastructure/Win32Helper.cs:877
// https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems
public static unsafe void OpenFolderAndSelectFile(string filePath)
{
ITEMIDLIST* pidlFolder = null;
ITEMIDLIST* pidlFile = null;
var folderPath = Path.GetDirectoryName(filePath);
try
{
var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);
if (hrFolder.Failed) throw new COMException("Failed to parse folder path", hrFolder);
var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, out _);
if (hrFile.Failed) throw new COMException("Failed to parse file path", hrFile);
var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);
if (hrSelect.Failed) throw new COMException("Failed to open folder and select item", hrSelect);
}
finally
{
if (pidlFile != null) PInvoke.CoTaskMemFree(pidlFile);
if (pidlFolder != null) PInvoke.CoTaskMemFree(pidlFolder);
}
}
#endregion
#region Win32 Dark Mode
/*
* Inspired by https://github.com/ysc3839/win32-darkmode
*/
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true)]
private static extern int SetPreferredAppMode(int appMode);View on GitHub (pinned to 7fc63b07bb)
Solutions
- Inspect the HRESULT (e.g. 0x80070005 access denied, 0x80004005 unspecified, 0x80040154 regdb_e_classnotreg) to classify.
- Restart Explorer (taskkill /f /im explorer.exe then start it) if it is hung.
- As a fallback, launch explorer.exe with the /select, argument: Process.Start("explorer.exe", $"/select,\"{filePath}\"").
- Ensure the call is made on a thread with the right apartment state and Explorer is running.
- Check Group Policy for 'Remove Folder Options' / Explorer-restriction settings.
Example fix
// before
var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);
if (hrSelect.Failed) throw new COMException("Failed to open folder and select item", hrSelect);
// after — fall back to the /select command if the shell call fails
var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);
if (hrSelect.Failed)
{
Log.Warn(nameof(Win32Helper), $"SHOpenFolderAndSelectItems failed: 0x{hrSelect:X}; using explorer /select");
System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{filePath}\"");
} Defensive patterns
Strategy: fallback
Validate before calling
null
Type guard
null
Try / catch
try { Win32Helper.OpenFolderAndSelectFile(filePath); }
catch (COMException ex) when (ex.Message.Contains("open folder and select"))
{ Log.Warn(...); Process.Start("explorer.exe", $"/select,\"{filePath}\""); } Prevention
- Always have a Process.Start("explorer.exe", "/select,...") fallback when the shell COM call fails.
- Restart Explorer if it is hung before retrying.
- Ensure the call runs on a thread with appropriate apartment state.
- Check Group Policy / third-party file-manager replacements that break SHOpenFolderAndSelectItems.
When it happens
Trigger: Explorer is not running or is hung and cannot service the COM call; a Group Policy or shell restriction blocks programmatic folder selection; the item is in a virtual/zip namespace Explorer can't navigate to; the folder window creation failed due to a shell extension crash; repeated rapid calls exhaust Explorer's capacity.
Common situations: Explorer process replaced by a third-party file manager that doesn't implement SHOpenFolderAndSelectItems; a corporate policy disabling Explorer automation; Explorer hung from a bad shell extension; calling in a context without an STA / message pump; rapid-fire selects from a fast user action.
Related errors
- Failed to get the desktop shell folder
- 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/66f2e477ebc89749.
Report an issue: GitHub.