【发布时间】:2021-09-04 14:02:30
【问题描述】:
所以我试图在 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))
【问题讨论】:
-
该错误通常意味着权限断开。为什么“python”安装在 AppData 下 - 它不应该在“C:\\Program files”下吗?是否为所有用户安装了“python”?您的应用是服务还是需要以管理员身份运行的东西?
-
你的应用是 UWP 应用吗?
-
是的,该应用是 uwp 应用
-
我尝试从 windows 商店运行 python 和在我的 venv 中运行 python。但两者都给了我同样的错误。到目前为止,我的应用程序非常基本,所以我认为我不需要任何特权来运行它。
-
你检查我的答案了吗?它解决了你的问题吗?
标签: c# windows uwp components system