日期:2014-05-18  浏览次数:20926 次

C#中调用ping命令怎么隐藏CMD的窗口
private void button1_Click(object sender, EventArgs e)
  {
  try
  {
  Process proc = new Process();

  proc.StartInfo.FileName = "ping.exe";
   
   
  proc.StartInfo.Arguments = "192.168.0.1";
   
  proc.StartInfo.UseShellExecute = false;
  proc.StartInfo.CreateNoWindow = false; 


  proc.StartInfo.RedirectStandardOutput = true;
  proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  
  proc.Start();

  string output = proc.StandardOutput.ReadToEnd();

  StreamWriter sw = new StreamWriter("c:/ping.txt");
  sw.Write(output);
  sw.Close();
  // MessageBox.Show(output);

  // MessageBox.Show((proc.ExitCode).ToString());  



  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }
 
  }

这样运行后,回弹出CMD的窗口,怎么隐藏?

------解决方案--------------------
C# code

…………
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
…………