How to change LAN Settings (proxy configuration) programmatically

后端 未结 5 660
萌比男神i
萌比男神i 2021-02-09 01:11

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

5条回答
  •  感情败类
    2021-02-09 01:59

    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);
        }
    

提交回复
热议问题