Win32Exception 访问被拒绝

Win32Exception Access Denied

所以我正在尝试 运行 python 在 C# 中编写代码。但是当我尝试执行命令时,我收到一条错误消息:

System.ComponentModel.Win32Exception: 'Access Denied'

代码:

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

错误发生在:

using (Process process = Process.Start(start))

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.

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