Friday, May 7, 2010

Disable IE proxy via C# Code or JAVA

 

sometimes, you might want to disable/enable the proxy via a program instead of clicking Tools->Options->Connections->LAN settings. popup 4 windows

How to do it?

basically the setting of the proxy is stored in Registry , all you need is to toggle the dword value of ProxyEnable.

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
 
"ProxyEnable"=dword:00000001  //1 means enable , 0 means disable

here is a simple C# Code.

private void EnableProxy(bool p)
      {
          string k = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
          Microsoft.Win32.RegistryKey regk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(k, true);
          if (p)
              regk.SetValue("ProxyEnable", 1, Microsoft.Win32.RegistryValueKind.DWord);
          else
              regk.SetValue("ProxyEnable", 0, Microsoft.Win32.RegistryValueKind.DWord);
          regk.Close();
      }

since there is no built-in library for registry manipulation. 
there is one open source library which do the same thing like C# library

jRegistryKey link

No comments:

 
Locations of visitors to this page