class PingUtil { public static string PingIP(string strip) { 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 pingstr; p.Start(); p.StandardInput.WriteLine("ping -n 1 " + strip); p.StandardInput.WriteLine("exit"); string stre = p.StandardOutput.ReadToEnd(); if (stre.IndexOf("(0%loss)") != -1) pingstr = "连接"; else if (stre.IndexOf("Destination host unreachable.") != -1) pingstr = "无法达到目的的主机"; else if (stre.IndexOf("Request timed out.") != -1) pingstr = "超时"; else if (stre.IndexOf("Unknown host") != -1) pingstr = "无法解析主机"; else pingstr = "网络连接成功!"; p.Close(); return pingstr; } }
public class ClassRunEXE { #region 基本构造函数 /// <summary> /// 构造函数 /// </summary> /// <param name="exeFileName">exe文件</param> /// <param name="Arguments">参数</param> // 用法:RunEXE("C:\Program Files\WinRAR\WinRAR.exe", "a -ep e:\test\20080612.rar E:\test\20080612\*.*") public static void RunEXE(string exeFileName, string arguments) { //声明一个程序信息类 System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo(); //设置外部程序名 Info.FileName = exeFileName; //设置外部程序的启动参数(命令行参数) Info.Arguments = arguments; //声明一个程序类 System.Diagnostics.Process Proc; try { //启动外部程序 Proc = System.Diagnostics.Process.Start(Info); } catch (Exception ex) { //MessageBox.Show("系统找不到指定的程序文件。"); System.Windows.Forms.MessageBox.Show(ex.Message, "系统找不到指定的程序文件。"); return; } //等待完成 Proc.WaitForExit(); } #endregion }