diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
index 6382ecd0f..9e8e203b3 100644
--- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
@@ -590,9 +590,10 @@ namespace Flow.Launcher.Plugin
/// Absolute file path. It can be an executable file or a script file
/// Working directory. If not specified, the current directory will be used
/// Optional arguments to pass to the process. If not specified, no arguments will be passed
- /// Whether to run the process as administrator
+ /// Whether to use shell to execute the process.
+ /// The verb to use when starting the process, e.g. "runas" for elevated permissions. If not specified, no verb will be used.
/// Whether process is started successfully
- 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 = "");
///
/// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application.
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 0746f3747..461f24aa7 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -577,16 +577,20 @@ 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 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;