|
首先,我们用使用Process类,来创建独立的进程,导入System.Diagnostics。实例一个Process类,启动一个独立进程。然后设置实例的属性。再传入Ping命令。在返回的流中就可以分析ping 命令的结果了。实现代码如下: 以下是引用片段: Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; string pingrst; p.Start(); p.StandardInput.WriteLine("ping -n 1 " + strIp);// strIp为IP地址。 p.StandardInput.WriteLine("exit"); |
|