I am writing a program to automatically switch my proxy address based on the network I am connected to.
I have so far got everything to work except the part that I have
I searched all through for this. But as I couldnt find, I had written the below code snippete that works for this purpose.
///
/// Checks or unchecks the IE Options Connection setting of "Automatically detect Proxy"
///
/// Provide 'true' if you want to check the 'Automatically detect Proxy' check box. To uncheck, pass 'false'
public void IEAutoDetectProxy(bool set)
{
// Setting Proxy information for IE Settings.
RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true);
byte[] defConnection = (byte[])RegKey.GetValue("DefaultConnectionSettings");
byte[] savedLegacySetting = (byte[])RegKey.GetValue("SavedLegacySettings");
if (set)
{
defConnection[8] = Convert.ToByte(9);
savedLegacySetting[8] = Convert.ToByte(9);
}
else
{
defConnection[8] = Convert.ToByte(1);
savedLegacySetting[8] = Convert.ToByte(1);
}
RegKey.SetValue("DefaultConnectionSettings", defConnection);
RegKey.SetValue("SavedLegacySettings", savedLegacySetting);
}