I am trying to write an application to be able to change a few registry values.Such as Dns Server,Defalut Gateway .I am using this code below for doing this
RegistryKey openSubKey = Registry.LocalMachine.OpenSubKey(path, true);
if (openSubKey != null)
{
//HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{F7DFBC05-B946-4C27-A58B-13BFB3FCC04E}
openSubKey.SetValue("IPAddress", "192.168.2.132");
openSubKey.SetValue("SubnetMask", "255.255.255.0");
openSubKey.SetValue("DefaultGateway", "192.168.2.2");
openSubKey.SetValue("NameServer", ""192.168.2.132,192.168.2.132"");
.Actually code works .I can see the new values in th registry as you can see
However when I check network connections I have realized that nothing changed but NameServer.What am I doing wrong here.
My suggestion is instead of direct registry manipulation, use WMI. See this StackOverflow post or this Code Project article on using WMI to update the Network Configuration.
Mostly you will have to work with Win32_NetworkAdapterConfiguration WMI object.