/// <summary> /// 隐藏方式运行DOS命令 /// </summary> /// <param name="command">DOS命令</param> public static void runcmd(string command) { Process process = new Process(); try { process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "/c" + command; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void button1_Click(object sender, EventArgs e) { string command = textBox1.Text.Trim(); runcmd(command); }
托一个文本框和一个按钮就可以测试