mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve api function
This commit is contained in:
parent
b8a697c266
commit
a0ebe2916f
2 changed files with 12 additions and 7 deletions
|
|
@ -590,9 +590,10 @@ namespace Flow.Launcher.Plugin
|
|||
/// <param name="filePath">Absolute file path. It can be an executable file or a script file</param>
|
||||
/// <param name="workingDirectory">Working directory. If not specified, the current directory will be used</param>
|
||||
/// <param name="arguments">Optional arguments to pass to the process. If not specified, no arguments will be passed</param>
|
||||
/// <param name="runAsAdmin">Whether to run the process as administrator</param>
|
||||
/// <param name="useShellExecute">Whether to use shell to execute the process.</param>
|
||||
/// <param name="verb">The verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used.</param>
|
||||
/// <returns>Whether process is started successfully</returns>
|
||||
public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false);
|
||||
public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool useShellExecute = true, string verb = "");
|
||||
|
||||
/// <summary>
|
||||
/// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application.
|
||||
|
|
|
|||
|
|
@ -577,16 +577,20 @@ 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 filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false)
|
||||
public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool useShellExecute = true, string verb = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
workingDirectory = string.IsNullOrEmpty(workingDirectory) ? Environment.CurrentDirectory : workingDirectory;
|
||||
|
||||
// Deelevate process if it is running as administrator
|
||||
if (Win32Helper.IsAdministrator() && !runAsAdmin)
|
||||
// Use command executer to run the process as desktop user if running as admin
|
||||
if (Win32Helper.IsAdministrator())
|
||||
{
|
||||
var result = Win32Helper.RunAsDesktopUser(filePath, workingDirectory, arguments, out var errorInfo);
|
||||
var result = Win32Helper.RunAsDesktopUser(
|
||||
Constant.CommandExecutablePath,
|
||||
Environment.CurrentDirectory,
|
||||
$"-StartProcess -FileName {filePath} -WorkingDirectory {workingDirectory} -Arguments {arguments} -UseShellExecute {useShellExecute} -Verb {verb}",
|
||||
out var errorInfo);
|
||||
if (!string.IsNullOrEmpty(errorInfo))
|
||||
{
|
||||
LogError(ClassName, $"Failed to start process {filePath} with error: {errorInfo}");
|
||||
|
|
@ -601,7 +605,7 @@ namespace Flow.Launcher
|
|||
WorkingDirectory = workingDirectory,
|
||||
Arguments = arguments,
|
||||
UseShellExecute = true,
|
||||
Verb = runAsAdmin ? "runas" : "",
|
||||
Verb = verb,
|
||||
};
|
||||
Process.Start(info)?.Dispose();
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue