因此,我试图在C#中运行python代码。但是,当我试图执行命令时,会收到一条错误消息:
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))发布于 2021-06-21 07:55:04
Process.Start法在UWP应用程序中不受支持。要从您的UWP应用程序运行exe文件,我建议您使用FullTrustProcessLauncher类。
首先,您需要复制exe文件并将其保存在UWP应用程序包中,例如资产文件夹。然后,请转到Manifest文件并添加runFullTrust受限功能.(App能力)。接下来,为UWP项目添加Windows扩展的引用。最后,您可以调用await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();从应用程序中启动exe文件。
https://stackoverflow.com/questions/68058773
复制相似问题