Set and cancel (C #. Net) the proxy server of ie5, IE6, IE7, and IE8

Source: Internet
Author: User

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.