nam
nam

Reputation: 23749

"Access denied" error when running a process from a UWP app

Question: In my following case, how can I use allowElevation capability from a UWP app to execute code with elevated privileges on my Windows 10 desktop with the 1809 update. This good article from Stefan Wick explains a similar use of such a capability from UWP app to a WPF app but in my case I'm using a Class Library instead of an exe.

Details: In my UWP project in VS2019, I've added .NET Standard Class Library project. My one UWP method is calling following method of my class library project. But due to Sandbox nature of UWP - as expected - the app is throwing Access denied error at line Process.Start() of the code.

public void Process_Start_Test()
{
   using (Process myProcess = new Process())
   {
       myProcess.StartInfo.UseShellExecute = false;
       myProcess.StartInfo.FileName = @"C:\DotNET2019\UWP\TestFolder\MyExeApp.exe";
       myProcess.StartInfo.CreateNoWindow = true;
       myProcess.Start(); //Access denied error here
   }
}

Upvotes: 0

Views: 716

Answers (1)

mm8
mm8

Reputation: 169160

You can't call Process.Start from a .NET Standard library that is referenced by your sandboxed UWP app.

You need to create an actual elevated process (.exe) that calls Process.Start as Stefan's blog post explains.

The full-trust .exe may of course reference your class library where the Process_Start_Test() is defined, but the method has to be called from the full-trust process regardless of whether it's defined in a library.

Upvotes: 2

Related Questions