Wednesday, September 12, 2012

Enable/Disable Proxy in IE through C#

// ProxyEnable == 0 means the proxy is on
// ProxyEnable == 1 means the proxy is off




string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
                string serverName = ConfigurationManager.AppSettings["proxyAddress"];
                int port = Convert.ToInt32(ConfigurationManager.AppSettings["proxyPort"]);
                string proxyy = serverName + ":" + port;

                RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
                RegKey.SetValue("ProxyServer", proxyy);
                RegKey.SetValue("ProxyEnable", 1);

                proxy = new WebProxy(proxyy, true);;
                proxy.Credentials = CredentialCache.DefaultCredentials;

                proxy.BypassProxyOnLocal = true;

2 comments:

  1. what is ConfigurationManager ?

    ReplyDelete
  2. The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class

    ReplyDelete