Skip to content

Commit 0d7d2aa

Browse files
authored
Fix: Fixed an issue where arguments weren’t passed when running shortcuts as admin (#15628)
1 parent 4af2d59 commit 0d7d2aa

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/Files.App/Helpers/Win32/Win32Helper.Process.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,40 @@ public static async Task<bool> InvokeWin32ComponentAsync(string applicationPath,
4646

4747
public static async Task<bool> InvokeWin32ComponentsAsync(IEnumerable<string> applicationPaths, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
4848
{
49-
Debug.WriteLine("Launching EXE in FullTrustProcess");
50-
5149
if (string.IsNullOrEmpty(workingDirectory))
52-
{
5350
workingDirectory = associatedInstance.ShellViewModel.WorkingDirectory;
54-
}
5551

5652
var application = applicationPaths.FirstOrDefault();
5753
if (string.IsNullOrEmpty(workingDirectory))
58-
{
5954
workingDirectory = associatedInstance?.ShellViewModel?.WorkingDirectory;
60-
}
6155

6256
if (runAsAdmin)
6357
{
64-
return await LaunchHelper.LaunchAppAsync(application, "RunAs", workingDirectory);
58+
// TODO In the long run, we should consider modifying HandleApplicationLaunch to handle this correctly.
59+
try
60+
{
61+
ProcessStartInfo startInfo = new ProcessStartInfo
62+
{
63+
FileName = application,
64+
Arguments = arguments,
65+
Verb = "runas",
66+
WorkingDirectory = workingDirectory,
67+
UseShellExecute = true
68+
};
69+
70+
Process process = new Process
71+
{
72+
StartInfo = startInfo
73+
};
74+
75+
process.Start();
76+
77+
return true;
78+
}
79+
catch (Exception)
80+
{
81+
return false;
82+
}
6583
}
6684
else
6785
{

0 commit comments

Comments
 (0)