This question already has answers here:
How to execute Process commands (or similar) using a Universal Windows Platform (UWP) App?
(2个答案)
3年前关闭。
我如何通过C#在Windows 10(现代)通用应用程序平台(UWP)上运行CMD命令?
我尝试使用此代码(适用于Windows窗体应用程序:
但我有一个错误:
和:
感谢大家
(2个答案)
3年前关闭。
我如何通过C#在Windows 10(现代)通用应用程序平台(UWP)上运行CMD命令?
我尝试使用此代码(适用于Windows窗体应用程序:
using System.Diagnostics;
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("the command");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
但我有一个错误:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) OneSpot C:\Users\reuve\Documents\Visual Studio 2015\Projects\app\app\MainPage.xaml.cs 37 Active
和:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Console' does not exist in the current context OneSpot C:\Users\reuve\Documents\Visual Studio 2015\Projects\app\app\MainPage.xaml.cs 49 Active
感谢大家
最佳答案
您不能从UWP应用程序启动外部可执行文件。安全模型可以防止这种情况。
您只能使用Launcher API提供的方法。
您可以使用LaunchFile或LaunchUri使用默认应用程序打开文件。系统将启动用户注册的应用程序以打开文件。
关于c# - 在Windows 10通用应用程序平台上运行CMD命令,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35462100/