“拒绝访问"从 UWP 应用运行进程时出错 [英] "Access denied" error when running a process from a UWP app

查看:25
本文介绍了“拒绝访问"从 UWP 应用运行进程时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:在我的以下案例中,我如何使用 allowElevation 功能来自 UWP 应用程序,以使用 1809 更新在我的 Windows 10 桌面上执行具有提升权限的代码.这篇来自 Stefan Wick 的好文章解释了从 UWP 应用到 WPF 应用的类似功能的使用但就我而言,我使用的是类库而不是 exe.

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.

详细信息:在 VS2019 的 UWP 项目中,我添加了 .NET Standard 类库项目.我的一个 UWP 方法正在调用我的类库项目的以下方法.但由于 UWP 的沙盒性质 - 正如预期的那样 - 应用程序在代码的 Process.Start() 行抛出 Access denied 错误.

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
   }
}

推荐答案

不能从沙盒 UWP 应用引用的 .NET Standard 库中调用 Process.Start.

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

您需要创建一个实际提升的进程 (.exe),它调用 Process.Start,如 Stefan 的博客文章所述.

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

完全信任 .exe 当然可以引用定义了 Process_Start_Test() 的类库,但是必须从完全信任中调用该方法进程不管它是否在库中定义.

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.

这篇关于“拒绝访问"从 UWP 应用运行进程时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆