Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/Files.App/Helpers/Win32/Win32Helper.Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,40 @@ public static async Task<bool> InvokeWin32ComponentAsync(string applicationPath,

public static async Task<bool> InvokeWin32ComponentsAsync(IEnumerable<string> applicationPaths, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
{
Debug.WriteLine("Launching EXE in FullTrustProcess");

if (string.IsNullOrEmpty(workingDirectory))
{
workingDirectory = associatedInstance.ShellViewModel.WorkingDirectory;
}

var application = applicationPaths.FirstOrDefault();
if (string.IsNullOrEmpty(workingDirectory))
{
workingDirectory = associatedInstance?.ShellViewModel?.WorkingDirectory;
}

if (runAsAdmin)
{
return await LaunchHelper.LaunchAppAsync(application, "RunAs", workingDirectory);
// TODO In the long run, we should consider modifying HandleApplicationLaunch to handle this correctly.
try
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = application,
Arguments = arguments,
Verb = "runas",
WorkingDirectory = workingDirectory,
UseShellExecute = true
};

Process process = new Process
{
StartInfo = startInfo
};

process.Start();

return true;
}
catch (Exception)
{
return false;
}
}
else
{
Expand Down