diff --git a/src/modules/launcher/Wox.Infrastructure/ShellLinkHelper.cs b/src/modules/launcher/Wox.Infrastructure/ShellLinkHelper.cs index 8688716db51a..b18a0f1e3c8d 100644 --- a/src/modules/launcher/Wox.Infrastructure/ShellLinkHelper.cs +++ b/src/modules/launcher/Wox.Infrastructure/ShellLinkHelper.cs @@ -136,13 +136,25 @@ public string RetrieveTargetPath(string path) var link = new ShellLink(); const int STGM_READ = 0; + // Make sure not to open exclusive handles. + // See: https://github.com/microsoft/WSL/issues/11276 + const int STGM_SHARE_DENY_NONE = 0x00000040; + const int STGM_TRANSACTED = 0x00010000; + try { - ((IPersistFile)link).Load(path, STGM_READ); + ((IPersistFile)link).Load(path, STGM_READ | STGM_SHARE_DENY_NONE | STGM_TRANSACTED); } catch (System.IO.FileNotFoundException ex) { - Log.Exception("Path could not be retrieved", ex, GetType(), path); + Log.Exception("Path could not be retrieved " + path, ex, GetType(), path); + Marshal.ReleaseComObject(link); + return string.Empty; + } + catch (System.Exception ex) + { + Log.Exception("Exception loading path " + path, ex, GetType(), path); + Marshal.ReleaseComObject(link); return string.Empty; }