diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index f9fc239a55d..9af5bfec873 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -193,51 +193,63 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas"; - ProcessStartInfo info; - if (_settings.Shell == Shell.Cmd) + ProcessStartInfo info = new() { - var arguments = _settings.LeaveShellOpen ? $"/k \"{command}\"" : $"/c \"{command}\" & pause"; - - info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, arguments, runAsAdministratorArg); - } - else if (_settings.Shell == Shell.Powershell) + Verb = runAsAdministratorArg, + WorkingDirectory = workingDirectory, + }; + switch (_settings.Shell) { - string arguments; - if (_settings.LeaveShellOpen) - { - arguments = $"-NoExit \"{command}\""; - } - else - { - arguments = $"\"{command} ; Read-Host -Prompt \\\"Press Enter to continue\\\"\""; - } + case Shell.Cmd: + { + info.FileName = "cmd.exe"; + info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c"); + info.ArgumentList.Add(command); + break; + } - info = ShellCommand.SetProcessStartInfo("powershell.exe", workingDirectory, arguments, runAsAdministratorArg); - } - else if (_settings.Shell == Shell.RunCommand) - { - var parts = command.Split(new[] { ' ' }, 2); - if (parts.Length == 2) - { - var filename = parts[0]; - if (ExistInPath(filename)) + case Shell.Powershell: { - var arguments = parts[1]; - info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsAdministratorArg); + info.FileName = "powershell.exe"; + if (_settings.LeaveShellOpen) + { + info.ArgumentList.Add("-NoExit"); + info.ArgumentList.Add(command); + } + else + { + info.ArgumentList.Add("-Command"); + info.ArgumentList.Add(command); + } + break; } - else + + case Shell.RunCommand: { - info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg); + var parts = command.Split(new[] { ' ' }, 2); + if (parts.Length == 2) + { + var filename = parts[0]; + if (ExistInPath(filename)) + { + var arguments = parts[1]; + info.FileName = filename; + info.ArgumentList.Add(arguments); + } + else + { + info.FileName = command; + } + } + else + { + info.FileName = command; + } + + break; } - } - else - { - info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg); - } - } - else - { - throw new NotImplementedException(); + default: + throw new NotImplementedException(); } info.UseShellExecute = true; diff --git a/Plugins/Flow.Launcher.Plugin.Shell/plugin.json b/Plugins/Flow.Launcher.Plugin.Shell/plugin.json index 6b20eeef9ef..b71dba2da25 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Shell/plugin.json @@ -4,7 +4,7 @@ "Name": "Shell", "Description": "Provide executing commands from Flow Launcher", "Author": "qianlifeng", - "Version": "1.4.5", + "Version": "1.4.6", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",