首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Win32Exception访问被拒绝

Win32Exception访问被拒绝
EN

Stack Overflow用户
提问于 2021-06-20 18:12:52
回答 1查看 1.4K关注 0票数 0

因此,我试图在C#中运行python代码。但是,当我试图执行命令时,会收到一条错误消息:

代码语言:javascript
复制
System.ComponentModel.Win32Exception: 'Access Denied'

代码:

代码语言:javascript
复制
private void run_cmd(string cmd, int args)
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = "C://Users//user//AppData//Local//Microsoft//WindowsApps//python.exe";
            start.Arguments = string.Format("{0} {1}", cmd, args);
            start.UseShellExecute = false;
            start.RedirectStandardOutput = true;
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = reader.ReadToEnd();
                    Console.Write(result);
                }
            }
        }

错误发生在:

代码语言:javascript
复制
using (Process process = Process.Start(start))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-21 07:55:04

Process.Start法在UWP应用程序中不受支持。要从您的UWP应用程序运行exe文件,我建议您使用FullTrustProcessLauncher类

首先,您需要复制exe文件并将其保存在UWP应用程序包中,例如资产文件夹。然后,请转到Manifest文件并添加runFullTrust受限功能.(App能力)。接下来,为UWP项目添加Windows扩展的引用。最后,您可以调用await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();从应用程序中启动exe文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68058773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档