private void ExecuteCMD(string cmd) { Process process = new Process(); try { process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; // process.StartInfo.CreateNoWindow = true; process.Start(); process.StandardInput.WriteLine(cmd); process.StandardInput.WriteLine("exit"); process.WaitForExit(); string readProOutResult = process.StandardOutput.ReadToEnd(); } catch (Exception ex) { MessageBox.Show("操作失败"); } finally { process.Close(); }
转自:http://www.cnblogs.com/chenleinet/archive/2011/07/19/2110601.html