首页  编辑  

改变代理服务器

Tags: /超级猛料/OS.操作系统/IE.扩展/IE设置和控制面板/   Date Created:

更改IE代理服务器设置,不重新启动IE,代码如下:

但如何设置某种协议为一特定地址呢,BYPASS参数怎么用?

其实在proxyserver中http=205.207.118.51:80;https=205.207.118.51:80;gopher=205.207.118.51:80;socks=205.207.118.51:80是分别设置,如果只有地址和端口则是所有协议使用相同地址

///Coder:Kingron

function ChangeProxy(const Proxy, Port,ByPass: string; const bEnabled: boolean = True): boolean;

var

 reg: Tregistry;

 info: INTERNET_PROXY_INFO;

 Fproxy:string;

begin

 Result := False;

 FProxy:=Format('%s:%s',[Proxy,Port]);

 reg := Tregistry.Create;

 try

   reg.RootKey := HKEY_CURRENT_USER;

   if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', True) then

   begin

     reg.Writestring('ProxyServer', Fproxy);

     reg.WriteInteger('ProxyEnable', integer(bEnabled));

     info.dwAccessType := INTERNET_OPEN_TYPE_PROXY;

     info.lpszProxy := pchar(proxy);

     info.lpszProxyBypass := pchar(ByPass);

     InternetSetOption(nil, INTERNET_OPTION_PROXY, @info, SizeOf(Info));

     InternetSetOption(nil, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);

//      InternetSetOption(nil, INTERNET_OPTION_REFRESH, nil, 0);

//      Sendmessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);

     Result:=True;

   end

 finally

   reg.CloseKey;

   reg.free;

 end;

end;

上面的代码只能更改LAN的设置,要更改拨号网络的设置,需要修改HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections下

各个连接的设置!

其中DefaultConnectionSettings表示默认的连接设置,SavedLegacySettings表示保存的设置的历史记录,其余的名称为拨号的连接设置信息!

已知该数据的格式:

偏移 0008 处,09 表示 "自动检测",01表示不"自动检测",05表示使用"自动配置脚本"

:feijun, 时间:2001-6-14 11:32:53, ID:566267

user urlmon,wininet;

procedure qiehuanproxy(const proxyname:string);

var info:TInternetProxyInfo;

 lngth:integer;

 h:integer;

 proxy :pChar;

 bypass :PChar;

 begin

 proxy:=pchar(proxyname);//proxy address:port

 bypass:=pChar('');

 info.dwAccessType := INTERNET_OPEN_TYPE_PROXY  ;

 info.lpszProxy :=proxy;

 info.lpszProxyBypass:=bypass;

 lngth:=sizeof(info);

  h:=UrlMkSetSessionOption(INTERNET_OPTION_PROXY ,@info,lngth,0);

end;

InternetSetOption(nil,INTERNET_OPTION_REFRESH, nil,0);

InternetSetOption(nil,INTERNET_OPTION_SETTINGS_CHANGED, nil,0);

*********************************************************************

unit WininetAppend;

interface

uses

 Windows;

type

 PInternetPerConnOption = ^INTERNET_PER_CONN_OPTION;

 INTERNET_PER_CONN_OPTION = record

   dwOption: DWORD;

   case Integer of

     0: (dwValue: DWORD);

     1: (pszValue:LPTSTR);

     2: (ftValue: FILETIME);

   end;

 PInternetPerConnOptionList = ^INTERNET_PER_CONN_OPTION_LIST;

 INTERNET_PER_CONN_OPTION_LIST = record

   dwSize        :DWORD;

   pszConnection :LPTSTR;

   dwOptionCount :DWORD;

   dwOptionError :DWORD;

   pOptions      :PInternetPerConnOption;

 end;

//

// Options used in INTERNET_PER_CONN_OPTON struct

//

const

 INTERNET_PER_CONN_FLAGS               = 1;

 INTERNET_PER_CONN_PROXY_SERVER        = 2;

 INTERNET_PER_CONN_PROXY_BYPASS        = 3;

 INTERNET_PER_CONN_AUTOCONFIG_URL      = 4;

 INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5;

//

// PER_CONN_FLAGS

//

 PROXY_TYPE_DIRECT         = $00000001;   // direct to net

 PROXY_TYPE_PROXY          = $00000002;   // via named proxy

 PROXY_TYPE_AUTO_PROXY_URL = $00000004;   // autoproxy URL

 PROXY_TYPE_AUTO_DETECT    = $00000008;   // use autoproxy detection

//

// PER_CONN_AUTODISCOVERY_FLAGS

//

 AUTO_PROXY_FLAG_USER_SET                  =      $00000001;   // user changed this setting

 AUTO_PROXY_FLAG_ALWAYS_DETECT             =      $00000002;   // force detection even when its not needed

 AUTO_PROXY_FLAG_DETECTION_RUN             =      $00000004;   // detection has been run

 AUTO_PROXY_FLAG_MIGRATED                  =      $00000008;   // migration has just been done

 AUTO_PROXY_FLAG_DONT_CACHE_PROXY_RESULT   =      $00000010;   // don't cache result of host=proxy name

 AUTO_PROXY_FLAG_CACHE_INIT_RUN            =      $00000020;   // don't initalize and run unless URL expired

 AUTO_PROXY_FLAG_DETECTION_SUSPECT         =      $00000040;   // if we're on a LAN & Modem, with only one IP, bad?!?

 INTERNET_OPTION_PER_CONNECTION_OPTION   = 75;

implementation

end.

////////////////////////////////////////

uses

 Wininet, WininetAppend;

function GetProxyInfo(var AutoDetect,AutoProxyUrl,

 DirectConnect,ProxyConnect:boolean;var AutoProxyUrlAddress,

 ByPassAddress,ProxyServer:String):boolean;

var

 nSize : DWORD;

 List  : INTERNET_PER_CONN_OPTION_LIST;

 Option: array[0..3] of INTERNET_PER_CONN_OPTION;

begin

 nSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);

 Option[0].dwOption := INTERNET_PER_CONN_AUTOCONFIG_URL;

 Option[1].dwOption := INTERNET_PER_CONN_FLAGS;

 Option[2].dwOption := INTERNET_PER_CONN_PROXY_BYPASS;

 Option[3].dwOption := INTERNET_PER_CONN_PROXY_SERVER;

 List.dwSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);

 List.pszConnection := nil;

 List.dwOptionCount := 4;

 List.dwOptionError := 0;

 List.pOptions := @Option;

 result := InternetQueryOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @List, nSize);

 if not result then exit;

 if(Option[0].pszValue <> nil) then

 begin

   AutoProxyUrlAddress := StrPas(Option[0].pszValue);

   GlobalFreePtr(Option[0].pszValue);

 end

 else

   AutoProxyUrlAddress := '';

 DirectConnect := (Option[1].dwValue and PROXY_TYPE_DIRECT ) = PROXY_TYPE_DIRECT;

 ProxyConnect := (Option[1].dwValue and PROXY_TYPE_PROXY ) = PROXY_TYPE_PROXY;

 AutoProxyUrl := (Option[1].dwValue and PROXY_TYPE_AUTO_PROXY_URL) = PROXY_TYPE_AUTO_PROXY_URL;

 AutoDetect := (Option[1].dwValue and PROXY_TYPE_AUTO_DETECT) = PROXY_TYPE_AUTO_DETECT;

 if(Option[2].pszValue <> nil) then

 begin

   ByPassAddress := StrPas(Option[2].pszValue);

   GlobalFreePtr(Option[2].pszValue);

 end

 else

   ByPassAddress := '';

 if(Option[3].pszValue <> nil) then

 begin

   ProxyServer := StrPas(Option[3].pszValue);

   GlobalFreePtr(Option[3].pszValue);

 end

 else

   ProxyServer := '';

end;

function SetProxyInfo(const ProxyConnect:boolean;const ByPassAddress,ProxyServer:String):boolean;

var

 nSize : DWORD;

 List  : INTERNET_PER_CONN_OPTION_LIST;

 Option: array[0..2] of INTERNET_PER_CONN_OPTION;

begin

 nSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);

 Option[0].dwOption := INTERNET_PER_CONN_FLAGS;

 if ProxyConnect then

   Option[0].dwValue := PROXY_TYPE_PROXY

 else

   Option[0].dwValue := PROXY_TYPE_DIRECT;

 Option[1].dwOption := INTERNET_PER_CONN_PROXY_BYPASS;

 Option[1].pszValue := PChar(ByPassAddress);

 Option[2].dwOption := INTERNET_PER_CONN_PROXY_SERVER;

 Option[2].pszValue := PChar(ProxyServer);

 List.dwSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);

 List.pszConnection := nil;

 List.dwOptionCount := 3;

 List.dwOptionError := 0;

 List.pOptions := @Option;

 result := InternetSetOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @List, nSize);

end;