Follow me on Twitter to receive updates, free scripts and ongoing announcements!

Delphi enable and disable proxy in IE

Written by Codes Tips on May 10, 2009 – 2:09 pm -

To change the proxy that you connect to internet by code in delphi you need to change the values of 2 fields from the folder settings of Internet Explorer in the registry. Basically you should change the registry values of 2 fields ProxyServer and ProxyEnable. First to use a proxy server you should enable the field ProxyEnable, by setting it to 1. Proxy server is the formatted like server:port and tell the browser through which server should connect.
You should include in the uses cause Registry.
Here is a sample function to change proxy server for internet explorer:

procedure EnableProxy( proxy:string; proxyp: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’,proxy+’:'+proxyp);
Reg.WriteInteger(’ProxyEnable’,1);
Reg.CloseKey;
end;
finally
Reg.Free;
end;

end;

To disable the proxy by in internet explorer you should set the field ProxyEnable to 0. Here is how to do it:

procedure DisableProxy;
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.WriteInteger(’ProxyEnable’,0);
Reg.CloseKey;
end;
finally
Reg.Free;
end;
end;


Tags: ,
Posted in Delphi |

Leave a Comment

You must be logged in to post a comment.


Plugintaylor.com - Plugintaylor and Frequently Asked Questions