3

how can i run CMD command on windows 10 (modern) Universal app Platform (UWP) via C#? i try using this code (it's works on windows form app:

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

but i have a error:

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

and:

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

Thanks everyone

1 Answers1

4

You cannot not launch external executable from your UWP application. This is prevented by the security model. You are restricted to the methods provided by the Launcher API.

You can open a file with its default application using LaunchFile or LaunchUri. The system will start the application registered by the user to open the file.

Vincent
  • 3,656
  • 1
  • 23
  • 32
  • Specific remarks of note: _**"Your app can't select the app that is launched. The user determines which app is launched. The user can select either a Universal Windows Platform (UWP) app or a Windows desktop app."**_ and _**"You can't launch file types that contain code or script if they are executed automatically by the operating system, such as, .exe, .msi, and .js files."**_ – kayleeFrye_onDeck Oct 11 '17 at 02:02