uses Registry, urlmon, wininet;
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
ChangeProxy('148.233.159.24','80','',true);
end;