IE proxy settings

Source: Internet
Author: User

// Todo
Class csetieproxy
{
Public:
Csetieproxy ()
{

}
Virtual ~ Csetieproxy ()
{

}
 
Public:
//
// Set proxy
//
Bool setproxy (cstring strproxyserver)
{
If (setproxyoption (strproxyserver) & enableconnetbylan ())
{
Return true;
}
Return false;
}

//
// Cancel proxy
//
Bool cancelproxy ()
{
If (disableconnectionproxy () & disableconnetbylan ())
{
Return true;
}
Return false;
}
 
//
// Get proxy (this function is to be developed)
//
Void getproxy ()
{
Getproxyoption ();
}
 
Protected:
//
// Set Internet proxy connection options
//
Bool setproxyoption (cstring strproxyserver)
{
Internet_per_conn_option_list list;
Internet_per_conn_option option [3];
Unsigned long nsize = sizeof (internet_per_conn_option_list );

Option [0]. dwoption = internet_per_conn_proxy_server;
Option [0]. value. pszvalue = (lptstr) (lpctstr) strproxyserver;

Option [1]. dwoption = internet_per_conn_flags;
Option [1]. value. dwvalue = proxy_type_proxy;
Option [1]. value. dwvalue | = proxy_type_direct;

// This option sets all the possible connection types for the client.
// This case specifies that the proxy can be used or direct connection is possible.
Option [2]. dwoption = internet_per_conn_proxy_bypass;
Option [2]. value. pszvalue = _ T ("<local> ");

List. dwsize = sizeof (internet_per_conn_option_list );
List. pszconnection = NULL;
List. dwoptioncount = 3;
List. dwoptionerror = 0;
List. poptions = option;

If (! Internetsetoption (null, internet_option_per_connection_option, & list, nsize ))
{
Return false;
}

Update ();

Return true;
}

//
// Obtain the Internet proxy connection Option
//
Void getproxyoption ()
{
Internet_per_conn_option_list ioptionlist; // Internet connection options
Internet_per_conn_option ioptions [3];
Ulong usize = sizeof (ioptionlist );

Ioptionlist. dwsize = usize;
Ioptionlist. pszconnection = NULL;
Ioptionlist. dwoptioncount = 3;
Ioptionlist. poptions = ioptions;

// Set proxy type direct or Proxy Server
Ioptions [0]. dwoption = internet_per_conn_flags;
Ioptions [1]. dwoption = internet_per_conn_proxy_server;
Ioptions [2]. dwoption = internet_per_conn_proxy_bypass;

If (internetqueryoption (null, internet_option_per_connection_option, (lpvoid) (& ioptionlist), & usize ))
{
Globalfree (ioptionlist. poptions [1]. value. pszvalue );
Globalfree (ioptionlist. poptions [2]. value. pszvalue );
Globalfree (ioptionlist. poptions [3]. value. pszvalue );
}
}

//
// Cancel ie proxy settings
//
Bool disableconnectionproxy ()
{
Internet_per_conn_option_list list;
Internet_per_conn_option option [1];
Unsigned long nsize = sizeof (internet_per_conn_option_list );

Option [0]. dwoption = internet_per_conn_flags;
Option [0]. value. dwvalue = proxy_type_direct;

List. dwsize = sizeof (internet_per_conn_option_list );
List. pszconnection = NULL;
List. dwoptioncount = 1;
List. dwoptionerror = 0;
List. poptions = option;

If (! Internetsetoption (null, internet_option_per_connection_option, & list, nsize ))
{
Return false;
}

Update ();

Return true;
}

// Make the proxy available
//
// Modify the IE dialing option to disable dialing
//
Bool enableconnetbylan ()
{
Hkey = openregister ();
If (null = hkey)
{
Return false;
}

Dword dw = false;
If (error_success! = Regsetvalueex (hkey, // subkey handle
_ T ("enableautodial"), // Value Name
0, // must be zero
REG_DWORD, // Value Type
(Lpbyte) & DW, // pointer to value data
Sizeof (DW )))
{
Regclosekey (hkey );
Return false;
}
Regclosekey (hkey );
Update ();

Return true;
}

// Make the agent unavailable
//
// Modify the IE dialing option to dialing
//
Bool disableconnetbylan ()
{
Hkey = openregister ();
If (null = hkey)
{
Return false;
}

Dword dw = true;
If (error_success! = Regsetvalueex (hkey, // subkey handle
_ T ("enableautodial"), // Value Name
0, // must be zero
REG_DWORD, // Value Type
(Lpbyte) & DW, // pointer to value data
Sizeof (DW )))
{
Regclosekey (hkey );
Return false;
}

Regclosekey (hkey );
Update ();

Return true;
}

// Open the registry key
Hkey csetieproxy: openregister ()
{
Hkey;
DWORD dwdisp;
Long lresult = 0;
Lresult = regcreatekeyex (HKEY_CURRENT_USER,
_ T ("software/Microsoft // windows // CurrentVersion/Internet Settings "),
0,
_ T (""),
0,
0,
Null,
& Hkey,
& Dwdisp );
If (error_success! = Lresult)
{
Hkey = NULL;
}

Return hkey;
}
 
// Update proxy
Void csetieproxy: Update ()
{
// Notification: the proxy changes in the Registry and starts the proxy next time you connect
Internetsetoption (null, internet_option_settings_changed, null, 0 );
// Read the agent from the Registry
Internetsetoption (null, internet_option_refresh, null, 0 );
}
};

To Enumerate dial-up connections, you can use rasenumconnections
// For details, see blog. csnd. Net/happyhell.

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.