Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a code for Changing Proxy Settings (Basically Stay Between Proxy Enable and Automatic LAN Setting)

C#
private void EnableProxy(bool p)
        {
            string k = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
            Microsoft.Win32.RegistryKey regk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(k, true);
            if (p)
                regk.SetValue("ProxyEnable", 1, Microsoft.Win32.RegistryValueKind.DWord);
            else
                regk.SetValue("ProxyEnable", 0, Microsoft.Win32.RegistryValueKind.DWord);
            regk.Close();
        }


and for Automatic LAN setting

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


It works but I still have to apply it manually. It changes the setting but I have to go to Internet Settings and say "OK" and "Apply", Please help
Posted

1 solution

In general, when you change system wide settings, you should notify the applications about this. In general, you can do this by broadcasting special kind of messages. All that are interested in that message, will be able to react - of course, if an application does not intercept this message, the notification won't reach it. In some cases there are special techniques to notify specific applications. In your case, you need to notify the system and Internet explorer as well.

You should consult this article: Change Internet Explorer 7 Proxy Setting without Restarting Internet Explorer[^]
 
Share this answer
 
Comments
KumarAbhishekJaiswal 5-Oct-15 6:08am    
Thanks for the hint. I found a way....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900