Question

So, I have a task to: 1. Delete all settings in Internet Connection Properties 2. Set Use Automatic Configuration Script to my script

This is my code, and sometimes it works and values are in IE, and sometimes values are not in IE. I am frustrated with this hectic behavior and wondering where is my error (not in DNA ;))

    RegistryKey registry = Registry.CurrentUser.OpenSubKey(
    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
    registry.SetValue("ProxyEnable", 0);
    registry.Close();

    RegistryKey registry2 = Registry.CurrentUser.OpenSubKey(
        "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true);
    registry2.DeleteValue("DefaultConnectionSettings", false);
    registry2.Close();

    RegistryKey registry3 = Registry.CurrentUser.OpenSubKey(
    @"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
    registry3.SetValue("AutoConfigURL", @"http://wwwwwwwww/configscript.pac", Microsoft.Win32.RegistryValueKind.String);
    registry3.SetValue("ProxyEnable", 000000, RegistryValueKind.DWord);
    registry3.Close();
Was it helpful?

Solution

I suspect that the issue you face has something to with stale values on the UI. The quickest way to check whether your settings are "sticky" is to open Internet options and going to Lan settings directly from control panel.

The following command will launch "internet options"

control inetcpl.cpl

Further if your machine belongs to some corporate domains, there might be group policies set by admins that periodically enforces some values for these parameters. In such cases, you might have to schedule a task for say every 10 minutes, and enforce values of your choice. (note: that is what I have been doing for quite some time)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top