Wykonanie komendy Wiersza polecenia (CMD)

Zagadnienie: Chcemy wykonać w tle komendę w wierszu polecenia
Rozwiązanie:

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(textBox_destination_path.Text + "\\Temp\\ServiceApp.exe /uninstall");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();

Tags: