I need to reset internet connection from the c# program like the way through user interface. So I go through google, and end up with the code below:
Target OS: windows xp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace netreset
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Runcommand("arp", "-d *");
Runcommand("ipconfig", "/flushdns");
Runcommand("ipconfig", "/registerdns");
Console.WriteLine(".");
}
private static void Runcommand(string filename, string parameter)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = filename;
info.Arguments = parameter;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit(1000);
}
}
}