Programmatically Set Proxy Address, Port, User, Password throught Windows Registry

Posted by Fábio Antunes on Stack Overflow See other posts from Stack Overflow or by Fábio Antunes
Published on 2010-08-05T18:01:19Z Indexed on 2010/12/26 3:54 UTC
Read the original article Hit count: 468

Filed under:
|
|

I'm writing a small C# application that will use Internet Explorer to interact with a couple a websites, with help from WatiN.

However, it will also require from time to time to use a proxy.

I've came across Programmatically Set Browser Proxy Settings in C#, but this only enables me to enter a proxy address, and I also need to enter a Proxy username and password. How can I do that?

Note:

  • It doesn't matter if a solution changes the entire system Internet settings. However, I would prefer to change only IE proxy settings (for any connection).
  • The solution has to work with IE8 and Windows XP SP3 or higher.
  • I'd like to have the possibility to read the Proxy settings first, so that later I can undo my changes.

EDIT

With the help of the Windows Registry accessible through Microsoft.Win32.RegistryKey, i was able to apply a proxy something like this:

RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:8080");

But how can i specify a username and a password to login at the proxy server?

I also noticed that IE doesn't refresh the Proxy details for its connections once the registry was changed how can i order IE to refresh its connection settings from the registry?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about internet-explorer