From fd2af3f983234d22ce6f24bff9e1261afd3f03f0 Mon Sep 17 00:00:00 2001 From: stnkl Date: Sat, 6 Feb 2021 11:05:55 +0100 Subject: [PATCH] Use process directory as working directory (#110) --- EverythingToolbar/Data/SearchResult.cs | 6 +++++- EverythingToolbar/Helpers/ShellUtils.cs | 4 ++-- EverythingToolbar/Rules.xaml.cs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/EverythingToolbar/Data/SearchResult.cs b/EverythingToolbar/Data/SearchResult.cs index ebce03484..c878370a3 100644 --- a/EverythingToolbar/Data/SearchResult.cs +++ b/EverythingToolbar/Data/SearchResult.cs @@ -35,7 +35,11 @@ public void Open() { try { - Process.Start(FullPathAndFileName); + Process.Start(new ProcessStartInfo(FullPathAndFileName) + { + UseShellExecute = true, + WorkingDirectory = IsFile ? Path : FullPathAndFileName + }); EverythingSearch.Instance.IncrementRunCount(FullPathAndFileName); } catch (Exception e) diff --git a/EverythingToolbar/Helpers/ShellUtils.cs b/EverythingToolbar/Helpers/ShellUtils.cs index a71f80e40..e0589de2d 100644 --- a/EverythingToolbar/Helpers/ShellUtils.cs +++ b/EverythingToolbar/Helpers/ShellUtils.cs @@ -92,7 +92,7 @@ private static extern bool CreateProcess( [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); - public static void CreateProcessFromCommandLine(string commandLine) + public static void CreateProcessFromCommandLine(string commandLine, string workingDirectory = null) { var si = new STARTUPINFO(); var pi = new PROCESS_INFORMATION(); @@ -105,7 +105,7 @@ public static void CreateProcessFromCommandLine(string commandLine) false, 0, IntPtr.Zero, - null, + workingDirectory, ref si, out pi); } diff --git a/EverythingToolbar/Rules.xaml.cs b/EverythingToolbar/Rules.xaml.cs index cbb35e40d..33770fa6c 100644 --- a/EverythingToolbar/Rules.xaml.cs +++ b/EverythingToolbar/Rules.xaml.cs @@ -185,7 +185,7 @@ public static bool HandleRule(SearchResult searchResult, string command="") command = command.Replace("%path%", "\"" + searchResult.Path + "\""); try { - ShellUtils.CreateProcessFromCommandLine(command); + ShellUtils.CreateProcessFromCommandLine(command, searchResult.Path); return true; } catch(Win32Exception)