So im trying to run python code in C#. But when I'm trying to execute the command I get a error message:
System.ComponentModel.Win32Exception: 'Access Denied'
Code:
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);
}
}
}
The error is happening at:
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.
First, you need to copy the exe file and save it in the UWP app package, for example, the Assets folder. Then please go to the Manifest file and add the runFullTrust restricted capability.(App capability). Next, add the reference of Windows Desktop Extensions for the UWP project. At last, you could call await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
to launch the exe file from your app.