How to click "OK" as soon as you change the IE software proxy

I installed my Internet Explorer proxy using the following code.

RegistryKey RegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
            RegKey.SetValue("ProxyServer", "proxyserver");
            RegKey.SetValue("ProxyEnable", 1);
            RegKey.SetValue("ProxyOverride", "domains;<local>", RegistryValueKind.String);

After running this code, I see that the proxy server name is available in the Internet Explorer proxy settings. But when I hit the webpage in my test environment, I don’t see it. I found a very strange behavior of Internet Explorer, which after installing the proxy server through this code, I need to click on the OK button in the LAN settings, and then click on the web page. I see it right.

I searched for him for 4-5 hours and am now very much confused by this. Any help would be greatly appreciated.

+3
source share
1 answer

There is an API for Internet Explorer that should be used to change settings.

Wininet Link: http://msdn.microsoft.com/en-us/library/aa385483(VS.85).aspx

After you change the proxy server settings, you must call the InternetSetOption function with update flags to force Internet Explorer to read the registry and reconfigure it. If you have already changed the values ​​in the registry, you can leave by calling the following function (RefreshInternetExplorerSettings) to trigger an IE update.

[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool InternetSetOption(
    IntPtr hInternet,
    SET_OPTIONS option,
    IntPtr buffer,
    int bufferLength);

    public enum SET_OPTIONS
    {            
        INTERNET_OPTION_REFRESH = 37,
        INTERNET_OPTION_SETTINGS_CHANGED = 39,
        INTERNET_OPTION_PER_CONNECTION_OPTION = 75
    };

    private static void RefreshInternetExplorerSettings()
    {
        InternetSetOption(IntPtr.Zero, SET_OPTIONS.INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
        InternetSetOption(IntPtr.Zero, SET_OPTIONS.INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
    }
+2
source

Source: https://habr.com/ru/post/1754326/


All Articles