0

I have code:

// Execute msi
Process process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(msiPath);
process.StartInfo.Arguments = $"  /passive /i {Path.GetFileName(msiPath)}";
process.StartInfo.Verb = "runas";
process.StartInfo.UseShellExecute = true;
process.Start();
process.WaitForExit();

But I have error:

UseShellExecute is not supported on this platform.

Or if I disable UseShellExecute

process.StartInfo.UseShellExecute = false;

Programm doesn't execute because of admin privileges

Sooo... How can I execute msi as admin in UWP?

  • this is not possible: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute – Chris Berlin Jul 05 '21 at 07:27
  • @ChrisBerlin I have to disagree with you. For some UWP apps in menu I can click "run as administrator". If I can't dynamically request permissions, in theory I can start app with admin permissions. But I don't know - how to make it in practice – Alrott SlimRG Jul 05 '21 at 08:28
  • Please check the API documentation that Chris Berlin posted, it clearly mentions that set the ProcessStartInfo.UseShellExecute Property will raise a **PlatformNotSupportedException** if you do it in UWP apps. The behavior you got is expected. – Roy Li - MSFT Jul 05 '21 at 08:47
  • Another thing is that you can't execute msi from a UWP app. Please try it on WPF or Win32 app. – Roy Li - MSFT Jul 05 '21 at 08:49
  • You can't directly do it from UWP - you'd have to set up a different exe in the same install folder to pass through as a workaround as outlined here: https://stackoverflow.com/questions/49189353/uwp-how-to-start-an-exe-file-that-is-located-in-specific-directory – T.Schwarz Jul 05 '21 at 09:37

1 Answers1

1

First, it is mentioned here-ProcessStartInfo.UseShellExecute Property that set the ProcessStartInfo.UseShellExecute Property will raise a PlatformNotSupportedException if you do it in UWP apps. The behavior you got is expected. Second, Process.Start Method is not supported in UWP apps. To run the exe file from your UWP app, I'd suggest you use FullTrustProcessLauncher Class.

First, you need to copy the exe file and save it in the UWP app package, for example, the Assets folder. Then please go to the Manifest file and add the runFullTrust restricted capability.(App capability). Next, add the reference of Windows Desktop Extensions for the UWP project. At last, you could call await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); to launch the exe file from your app.

Roy Li - MSFT
  • 8,043
  • 1
  • 7
  • 13