From e3197799d6eb40e69b6b8cf39811469784c1424d Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:46:49 -0400 Subject: [PATCH 1/3] Fix: Fixed an issue where args weren't passed when shortcut was run as admin --- .../Helpers/Win32/Win32Helper.Process.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs index 46d3dc99e50c..5bd3b1c6af4f 100644 --- a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs +++ b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs @@ -46,22 +46,33 @@ public static async Task InvokeWin32ComponentAsync(string applicationPath, public static async Task InvokeWin32ComponentsAsync(IEnumerable applicationPaths, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null) { - Debug.WriteLine("Launching EXE in FullTrustProcess"); - if (string.IsNullOrEmpty(workingDirectory)) - { workingDirectory = associatedInstance.FilesystemViewModel.WorkingDirectory; - } var application = applicationPaths.FirstOrDefault(); if (string.IsNullOrEmpty(workingDirectory)) - { workingDirectory = associatedInstance?.FilesystemViewModel?.WorkingDirectory; - } if (runAsAdmin) { - return await LaunchHelper.LaunchAppAsync(application, "RunAs", workingDirectory); + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = application, + Arguments = arguments, + Verb = "runas", + WorkingDirectory = workingDirectory, + UseShellExecute = true + }; + + Process process = new Process + { + StartInfo = startInfo + }; + + process.Start(); + process.WaitForExit(); + + return true; } else { From 5e5a47f1e2abc149d77a2a108d31800ffc5a453c Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 19 Jun 2024 21:28:20 -0400 Subject: [PATCH 2/3] Update Win32Helper.Process.cs --- src/Files.App/Helpers/Win32/Win32Helper.Process.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs index 5bd3b1c6af4f..b7e2a4c4f661 100644 --- a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs +++ b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs @@ -55,6 +55,8 @@ public static async Task InvokeWin32ComponentsAsync(IEnumerable ap if (runAsAdmin) { + // TODO In the long run, we should consider modifying HandleApplicationLaunch to handle this correctly. + ProcessStartInfo startInfo = new ProcessStartInfo { FileName = application, From f7dcbe0ff8334e0d8dd2f7344f7b89f1cadc73c6 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 23 Jun 2024 18:12:47 -0400 Subject: [PATCH 3/3] Update Win32Helper.Process.cs --- .../Helpers/Win32/Win32Helper.Process.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs index b7e2a4c4f661..6a523de77e46 100644 --- a/src/Files.App/Helpers/Win32/Win32Helper.Process.cs +++ b/src/Files.App/Helpers/Win32/Win32Helper.Process.cs @@ -56,25 +56,30 @@ public static async Task InvokeWin32ComponentsAsync(IEnumerable ap if (runAsAdmin) { // TODO In the long run, we should consider modifying HandleApplicationLaunch to handle this correctly. - - ProcessStartInfo startInfo = new ProcessStartInfo - { - FileName = application, - Arguments = arguments, - Verb = "runas", - WorkingDirectory = workingDirectory, - UseShellExecute = true - }; - - Process process = new Process + try { - StartInfo = startInfo - }; + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = application, + Arguments = arguments, + Verb = "runas", + WorkingDirectory = workingDirectory, + UseShellExecute = true + }; + + Process process = new Process + { + StartInfo = startInfo + }; - process.Start(); - process.WaitForExit(); + process.Start(); - return true; + return true; + } + catch (Exception) + { + return false; + } } else {