中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C#修復(fù)網(wǎng)絡(luò)連接代碼

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
namespace 修復(fù)網(wǎng)絡(luò)連接
{
  public partial class form1 : Form
  {
  DateTime ds;
  int timescan;
  System.Diagnostics.Process p=new System.Diagnostics.Process(); 
  public form1()
  {
  InitializeComponent();
     
  }
 
  private void renew_Click(object sender, EventArgs e)
  {
 
  initial_timer();  
 
  }
 
  public void rebuild_con()
  {
  //p = new System.Diagnostics.Process();
 
  p.StartInfo.FileName = "cmd.exe";
  //p.StartInfo.FileName = "f:\\test.bat";
 
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardInput = true;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.CreateNoWindow = true;
  p.Start();
  p.StandardInput.WriteLine("ipconfig /release");
  p.StandardInput.WriteLine("ipconfig /renew");
  p.StandardInput.WriteLine("arp -d*");
  p.StandardInput.WriteLine("nbtstat -r");
  p.StandardInput.WriteLine("nbtstat -rr");
  p.StandardInput.WriteLine("ipconfig/ flushdns");
  //MessageBox.Show(p.StandardOutput.ReadToEnd().ToString());
 
  }
  public string NetStatus()
  {
  ManagementObjectCollection objects;
  string status = "";
  ManagementObjectSearcher searcher = new ManagementObjectSearcher();
  searcher.Query.QueryString = "Select * From Win32_NetworkAdapter ";
  objects = searcher.Get();
  foreach (ManagementObject obj in objects)
  {
  foreach (PropertyData p in obj.Properties)
  {
  if (p.Name.Equals("NetConnectionStatus"))
  {
  if (p.Value != null)
  {
  status = p.Value.ToString();
  }
  }
  }
  }
  switch (status)
  {
  case "0":
  return "Disconnected";
  case "1":
  return "Connecting ...";
  case "2":
  return "Connected";
  case "3":
  return "Disconnecting ...";
  case "4":
  return "Hardware not present";
  case "5":
  return "Hardware disabled";
  case "6":
  return "Hardware malfunction";
  case "7":
  return "Media disconnected";
  case "8":
  return "Authenticating";
  case "9":
  return "Authentication succeeded";
  case "10":
  return "Authentication failed";
  default:
  return "";
  }
     
  }
 
     
 
  private void timer1_Tick(object sender, EventArgs e)
  {
  rebuild_con();
     
     
  richTextBox1.Text += "第" + (++timescan).ToString() + "次修復(fù)......";
  if (timescan % 5 == 0)
  {
  richTextBox1.Text += "\n";
  }
     
  string sta = NetStatus();
  while (sta == "Connected")
  {
 
  stp_exe();
  richTextBox1.Text += " \n修復(fù)成功!"+"\n已停止修復(fù)!";
  break;
 
  }
  }
 
  private void button1_Click(object sender, EventArgs e)
  {
  stp_exe();
  }
 
  private void timer2_Tick(object sender, EventArgs e)
  {
  int xv = progressBar1.Value == progressBar1.Maximum ? progressBar1.Value = 0 : progressBar1.Value++;
  }
  public void stp_exe()
  {
  timer1.Stop();
  timer2.Stop();
  progressBar1.Visible = false;
  label2.Visible = false;
  }
  public void initial_timer()
  {
     
  try
  {
  int j = int.Parse(textBox1.Text) * 1000;
  if (j < 5000)
  {
  MessageBox.Show("時(shí)間間隔過(guò)短,數(shù)值不得小于5秒!");
  return;
  }
  timer1.Interval = j;
  }
  catch (Exception ex)
  {
  MessageBox.Show("請(qǐng)輸入數(shù)字類型字符!" + ex.ToString().Remove(60) + "......");
  return;
  }
     
  timer2.Interval = 500;
  timer1.Start();
  timer2.Start();
  progressBar1.Minimum = 0;
  progressBar1.Maximum = 20;
  progressBar1.Visible = true;
  label2.Visible = true;
  }
  }
}

標(biāo)簽: dns 網(wǎng)絡(luò)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:C# 選擇法排序演示

下一篇:C# 操作系統(tǒng)服務(wù)(service)代碼