Reputation: 4216
I am trying to change the proxy settings to Enabled/Disabled for Internet Explorer programatically using C#. This to toggele between web sites that would require proxy or not.
My Code:
string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
RegKey.SetValue("ProxyEnable", 1);
Most articles I referred to for updating the registry indicate there is a risk of doing so.
I want to know
What are the risks involved in executing the above code
Is there any mitigation I can do to cover the risks. For example, taking a registry backup for the particular key.
Upvotes: 1
Views: 1106
Reputation: 5620
The registry is an environment that is controlled by the OS and may be subject of unexpectable updates from it. I think that the main risk is to be unable to know what really happens with your data (for example : if Windows thinks it is a good idea to reset or overwrite your values, you lose it all).
Also, like someone said in a comment to another answer, invalid entries may lead to data loss, especially if your data exceeds the maximum length allowed by the registry.
If you need to modify the registry, you may test if the key do exist and keep trace of original values before overwriting. Of course, you need to be sure that altering the key won't have unexpected effects.
Upvotes: 1
Reputation: 64638
The risk of changing the registry is simply that you can damage the system. If you really want to run it on a customers machine:
Upvotes: 1