Support createNoWindow for start process api

This commit is contained in:
Jack251970 2025-06-15 16:22:56 +08:00
parent 911999810c
commit 3493446d3e
2 changed files with 15 additions and 6 deletions

View file

@ -613,8 +613,9 @@ namespace Flow.Launcher.Plugin
/// <param name="arguments">Optional arguments to pass to the process. If not specified, no arguments will be passed</param>
/// <param name="useShellExecute">Whether to use shell to execute the process</param>
/// <param name="verb">Verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used.</param>
/// <param name="createNoWindow">Whether to create console window</param>
/// <returns>Whether process is started successfully</returns>
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);
/// <summary>
/// Start a process with support for handling administrative privileges
@ -627,7 +628,8 @@ namespace Flow.Launcher.Plugin
/// <param name="argumentList">Optional argument list to pass to the process. If not specified, no arguments will be passed</param>
/// <param name="useShellExecute">Whether to use shell to execute the process</param>
/// <param name="verb">Verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used.</param>
/// <param name="createNoWindow">Whether to create console window</param>
/// <returns>Whether process is started successfully</returns>
public bool StartProcess(string fileName, string workingDirectory = "", Collection<string> argumentList = null, bool useShellExecute = false, string verb = "");
public bool StartProcess(string fileName, string workingDirectory = "", Collection<string> argumentList = null, bool useShellExecute = false, string verb = "", bool createNoWindow = false);
}
}

View file

@ -585,7 +585,7 @@ namespace Flow.Launcher
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> 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<string> argumentList = null, bool useShellExecute = false, string verb = "") =>
StartProcess(fileName, workingDirectory, JoinArgumentList(argumentList), useShellExecute, verb);
public bool StartProcess(string fileName, string workingDirectory = "", Collection<string> argumentList = null, bool useShellExecute = false, string verb = "", bool createNoWindow = false) =>
StartProcess(fileName, workingDirectory, JoinArgumentList(argumentList), useShellExecute, verb, createNoWindow);
private static string AddDoubleQuotes(string arg)
{