2011-12-14 调用cmd并获得输入输出+网络访问

System.Diagnostics.Process pro = new System.Diagnostics.Process();

 pro.StartInfo.FileName = "cmd.exe";

 pro.StartInfo.UseShellExecute = false;

 pro.StartInfo.RedirectStandardInput = true;

 pro.StartInfo.RedirectStandardOutput = true;

 pro.StartInfo.CreateNoWindow = true;

 pro.Start();

 //pro.StandardInput.WriteLine("net use \\\\202.149.225.121\\ipc$ \"AISchina_Admin\" /user:\"administrator\"");

 pro.StandardInput.WriteLine("cd D:\\程序\\5千png");

 pro.StandardInput.WriteLine("dir *.*");

StreamReader reader = pro.StandardOutput;

  // 截取输出流 pro.StandardInput.WriteLine("exit");

string line = reader.ReadLine();

// 每次读一行 while (!reader.EndOfStream)  // 不为空则读取 {    textBox2.AppendText(line + Environment.NewLine);

  // Environment .NewLine 换行    line = reader.ReadLine();

 }pro.WaitForExit();

 pro.Close();

 

删除网络连接

net use */del

 

用ping命令快速判断地址是否合法

string ip = mapUrl.Substring(2, end - 2);

System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingStatus = null;
try
{
pingStatus = ping.Send(ip, 1000);
}
catch (Exception ex)
{
string p = ex.Message;
}
if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) //先ping命令快速测一下IP是否有效
{
}
else
{
}
}

 

posted on 2016-10-15 18:44  mol1995  阅读(190)  评论(0编辑  收藏  举报

导航