本文整理自网络,侵删。
uses UrlMon, WinInet,registry;
//设置代理function ChangeProxy(const Proxy,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]); Fproxy := Proxy; 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 :=pansichar(proxy); info.lpszProxyBypass :=pansichar(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;{调用:
//设置代理ChangeProxy('192.168.1.2:8080','1',true);//取消代理ChangeProxy('192.168.1.2:8080','1',False);}
相关阅读 >>
Delphi 如何判断clipboard剪切板中的内容的类型
Delphi 10 seattle中使用本地通知,请使用tnotificationcenter组件
Delphi实现使用tidhttp控件向https地址post请求
更多相关阅读请进入《Delphi》频道 >>