C# - Programmatically Reset IP configuration to default

Following sample code will reset Internet Protocol version 4(Tcp/Ipv4) Properties to
Obtain an IP address automatically and Obtain DNS server automatically

private void RunCommand(String commandLineArgs)
{
System.Diagnostics.Process objProcess = new System.Diagnostics.Process();
objProcess.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe";
//objProcess.StartInfo.UseShellExecute = false;
objProcess.StartInfo.Arguments = commandLineArgs;
objProcess.StartInfo.CreateNoWindow = false;
if (objProcess.StartInfo.Arguments.Length > 0)
{
objProcess.Start();
do
{
Thread.Sleep(100);
} while (!objProcess.HasExited);
}
if (objProcess.ExitCode == 0)
MessageBox.Show("Installed successfully.....");
else
MessageBox.Show("Oops smthng missed :( please try again........");
objProcess.Close();
}
private void button1_Click(object sender, EventArgs e)
{
RunCommand("/c netsh interface ip set address \"Local Area Connection\" dhcp");
RunCommand("/c netsh interface ip set DNS \"Local Area Connection\" dhcp");
}

Comments

Popular posts from this blog

Using Java Script detect if OS is 64 bit version or 32 bit.

Get correct OS version on win 8.1 without using GetVesionEx API (deprecated )