From 3493446d3ec8c3e2358e4557469791e3a7822280 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 15 Jun 2025 16:22:56 +0800 Subject: [PATCH] Support createNoWindow for start process api --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 6 ++++-- Flow.Launcher/PublicAPIInstance.cs | 15 +++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index fb8a131ea..788255cfb 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -613,8 +613,9 @@ namespace Flow.Launcher.Plugin /// Optional arguments to pass to the process. If not specified, no arguments will be passed /// Whether to use shell to execute the process /// Verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used. + /// Whether to create console window /// Whether process is started successfully - public bool StartProcess(string fileName, string workingDirectory = "", string arguments = "", bool useShellExecute = false, string verb = ""); + public bool StartProcess(string fileName, string workingDirectory = "", string arguments = "", bool useShellExecute = false, string verb = "", bool createNoWindow = false); /// /// Start a process with support for handling administrative privileges @@ -627,7 +628,8 @@ namespace Flow.Launcher.Plugin /// Optional argument list to pass to the process. If not specified, no arguments will be passed /// Whether to use shell to execute the process /// Verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used. + /// Whether to create console window /// Whether process is started successfully - public bool StartProcess(string fileName, string workingDirectory = "", Collection argumentList = null, bool useShellExecute = false, string verb = ""); + public bool StartProcess(string fileName, string workingDirectory = "", Collection argumentList = null, bool useShellExecute = false, string verb = "", bool createNoWindow = false); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index dbd8faf1c..50a5f8311 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -585,7 +585,7 @@ namespace Flow.Launcher public Task StopwatchLogInfoAsync(string className, string message, Func action, [CallerMemberName] string methodName = "") => Stopwatch.InfoAsync(className, message, action, methodName); - public bool StartProcess(string fileName, string workingDirectory = "", string arguments = "", bool useShellExecute = false, string verb = "") + public bool StartProcess(string fileName, string workingDirectory = "", string arguments = "", bool useShellExecute = false, string verb = "", bool createNoWindow = false) { try { @@ -597,7 +597,13 @@ namespace Flow.Launcher var result = Win32Helper.RunAsDesktopUser( Constant.CommandExecutablePath, Environment.CurrentDirectory, - $"-StartProcess -FileName {AddDoubleQuotes(fileName)} -WorkingDirectory {AddDoubleQuotes(workingDirectory)} -Arguments {AddDoubleQuotes(arguments)} -UseShellExecute {useShellExecute} -Verb {AddDoubleQuotes(verb)}", + $"-StartProcess " + + $"-FileName {AddDoubleQuotes(fileName)} " + + $"-WorkingDirectory {AddDoubleQuotes(workingDirectory)} " + + $"-Arguments {AddDoubleQuotes(arguments)} " + + $"-UseShellExecute {useShellExecute} " + + $"-Verb {AddDoubleQuotes(verb)} " + + $"-CreateNoWindow {createNoWindow}", false, true, // Do not show the command window out var errorInfo); @@ -616,6 +622,7 @@ namespace Flow.Launcher Arguments = arguments, UseShellExecute = useShellExecute, Verb = verb, + CreateNoWindow = createNoWindow }; Process.Start(info)?.Dispose(); return true; @@ -627,8 +634,8 @@ namespace Flow.Launcher } } - public bool StartProcess(string fileName, string workingDirectory = "", Collection argumentList = null, bool useShellExecute = false, string verb = "") => - StartProcess(fileName, workingDirectory, JoinArgumentList(argumentList), useShellExecute, verb); + public bool StartProcess(string fileName, string workingDirectory = "", Collection argumentList = null, bool useShellExecute = false, string verb = "", bool createNoWindow = false) => + StartProcess(fileName, workingDirectory, JoinArgumentList(argumentList), useShellExecute, verb, createNoWindow); private static string AddDoubleQuotes(string arg) {