mrk_raj
asked on
Retreiving the IE's Proxy Settings.
Hai Experts,
How can I retreive the Intenet Settings ( details of Proxy settings.. ) found in the Internet Explorer through a Delphi application?. Is there any Windows API for this?.
Please help...
How can I retreive the Intenet Settings ( details of Proxy settings.. ) found in the Internet Explorer through a Delphi application?. Is there any Windows API for this?.
Please help...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use TRegistry.
I think IE's proxy settings are under HKEY_CURRENT_USER\Software \Microsoft \Windows\C urrentVers ion\Intern et Settings
The values in this registry key should tell you everything,
the proxy name, port, whether it's enabled, the protocol..
etc.
Code snippet:
-------------------------- ---------- ---------- -------
type
TMyProxySettings = record
Server: string[255];
Port: integer;
Enabled: boolean;
end;
function GetProxySettings: TMyProxySettings;
const
IE_REG_KEY = 'Software\Microsoft\Window s\CurrentV ersion\Int ernet Settings';
DEFAULT_PORT: integer = 80;
var
reg: TRegistry;
cp: integer;
s: string;
begin
reg := TRegistry.Create;
try
with reg do
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey(IE_REG_KEY,false) then
begin
//get server name & port (usually combined)
s := ReadString('ProxyServer',' ');
cp := Pos(':',s);
if cp > 0 then
begin
result.Server := Copy(s,1,cp-1);
result.Port := StrToIntDef(Copy(s,cp+1,le ngth(s)-cp ),DEFAULT_ PORT);
end
else
begin
result.Server := s;
result.Port := DEFAULT_PORT;
end;
//get proxy enabled state
cp := ReadInteger('ProxyEnable', 0);
result.Enabled := cp > 0;
//all done
CloseKey;
end
else
begin
result.Server := '';
result.Port := DEFAULT_PORT;
end;
end;
finally
reg.free;
end;
end;
-------------------------- ---------- ---------- ----------
Hope this helps,
rondi
I think IE's proxy settings are under HKEY_CURRENT_USER\Software
The values in this registry key should tell you everything,
the proxy name, port, whether it's enabled, the protocol..
etc.
Code snippet:
--------------------------
type
TMyProxySettings = record
Server: string[255];
Port: integer;
Enabled: boolean;
end;
function GetProxySettings: TMyProxySettings;
const
IE_REG_KEY = 'Software\Microsoft\Window
DEFAULT_PORT: integer = 80;
var
reg: TRegistry;
cp: integer;
s: string;
begin
reg := TRegistry.Create;
try
with reg do
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey(IE_REG_KEY,false) then
begin
//get server name & port (usually combined)
s := ReadString('ProxyServer','
cp := Pos(':',s);
if cp > 0 then
begin
result.Server := Copy(s,1,cp-1);
result.Port := StrToIntDef(Copy(s,cp+1,le
end
else
begin
result.Server := s;
result.Port := DEFAULT_PORT;
end;
//get proxy enabled state
cp := ReadInteger('ProxyEnable',
result.Enabled := cp > 0;
//all done
CloseKey;
end
else
begin
result.Server := '';
result.Port := DEFAULT_PORT;
end;
end;
finally
reg.free;
end;
end;
--------------------------
Hope this helps,
rondi
Hello
I post a comment in your previous quesiotn about the same thing, u posted ur quesiont twice, here's what i wrote there
procedure TForm1.Button1Click(Sender : TObject);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\Micr osoft\Wind ows\Curren tVersion\I nternet Settings',false);
Edit1.Text :=Reg.ReadString('ProxySer ver');
end;
Best regards
Mohammed Nasman
I post a comment in your previous quesiotn about the same thing, u posted ur quesiont twice, here's what i wrote there
procedure TForm1.Button1Click(Sender
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('Software\Micr
Edit1.Text :=Reg.ReadString('ProxySer
end;
Best regards
Mohammed Nasman
ASKER
Thank Rondi for sending me the answer & thank you one and all who has sent comments about my quetion.
ASKER
Thank Rondi for sending me the answer & thank you one and all who has sent comments about my quetion.
... however in answer to your question "Is there any Windows API for this?" the answer is "yes". If you want to investigate InternetQueryOption and rest of the Internet API further can I recommend this link.
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/wininet/overview/common.asp
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/wininet/overview/common.asp
procedure GetDefaultProxyServer(var Server, ByPass: string; var Port: Integer);
const
BUF_SIZE: DWORD = 500;
var
ProxyInfo: PInternetProxyInfo;
Buffer: Pointer;
begin
GetMem(Buffer, BUF_SIZE);
try
if not InternetQueryOption(nil, INTERNET_OPTION_PROXY, Buffer, BUF_SIZE) then
RaiseLastWin32Error;
ProxyInfo := Buffer;
ByPass := ProxyInfo^.lpszProxyBypass
if (ProxyInfo^.lpszProxy = '') then begin
Server := '';
Port := 0;
end else with TStringTokenizer.Create(Pr
Server := NextToken;
if HasMoreTokens then
Port := StrToInt(NextToken)
else
Port := 0;
finally
Free;
end;
finally
FreeMem(Buffer);
end;
end;