//SetReg负责读写注册表
procedure TSetProxy.SetReg(FMProxy:string);
var
reg: Tregistry;
begin
reg:=Tregistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', True) then
begin
reg.Writestring('ProxyServer', FMproxy);
reg.WriteInteger('ProxyEnable', integer(true));
end
finally
reg.CloseKey;
reg.free;
end;
end;
constructor TSetProxy.Create(Proxy,Port:string);
begin
self.Proxy:=Proxy;
self.port:=Port;
end;
//
// 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?!?
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);
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;