本文說明了用delphi設置IE浏覽器的代理服務。
參數說明:
Proxy:代理服務器 IP 地址;
Port:端口號;
ByPass:對所有的協議均使用相同的代理服務器;
bEnabled:是否使用代理服務器(代理服務器是否生效)、
[delphi] // uses Wininet, registry;
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);
Result:=True;
end
finally
reg.CloseKey;
reg.free;
end;
end;
具體的調用:
[delphi] 設置:
procedure TForm1.Button1Click(Sender: TObject);
begin
ChangeProxy('202.99.29.27','80','1',true)
end;
取消:
procedure TForm1.Button2Click(Sender: TObject);
begin
ChangeProxy('202.99.29.27','80','1',false)
end;
摘自 #Define