To update all IE instances in real time, you must call the following API:
[Dllimport ("wininet. dll", setlasterror = true)]
Private Static extern bool internetsetoption (intptr hinternet, int dwoption, intptr lpbuffer, int lpdwbufferlength );
Then refresh the iesettings:
Private Static void refreshiesettings ()
{
Const int internet_option_refresh = 0x000025;
Const int internet_option_settings_changed = 0x000027;
Internetsetoption (intptr. Zero, internet_option_settings_changed, intptr. Zero, 0 );
Internetsetoption (intptr. Zero, internet_option_refresh, intptr. Zero, 0 );
}
Finally, write the settings of IE in the registry:
Public static void setieproxy (proxy)
{
String proxyip = "";
Proxyip = string. Format ("{0 }:{ 1}", proxy. proxyaddr, proxy. proxyport );
Registrykey rk = registry. currentuser. opensubkey (@ "software/Microsoft/Windows/CurrentVersion/Internet Settings", true );
Rk. setvalue ("proxyenable", 1 );
Rk. setvalue ("proxyserver", proxyip );
Rk. Close ();
Refreshiesettings ();
}
Public static void cancelieproxy ()
{
Registrykey rk = registry. currentuser. opensubkey (@ "software/Microsoft/Windows/CurrentVersion/Internet Settings", true );
Rk. setvalue ("proxyenable", 0 );
Rk. Close ();
Refreshiesettings ();
}
Public class proxy
{
Private string proxyname;
Private string proxyaddr;
Private int port;
Public proxy (string name, string ADDR, int port)
{
This. proxyname = Name;
This. proxyaddr = ADDR;
This. Port = port;
}
Public String proxyname {get {return proxyname ;}}
Public String proxyaddr {get {return proxyaddr ;}}
Public int proxyport {get {return port ;}}
Public override string tostring ()
{
Return proxyname;
}
}