Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retreiving the IE's Proxy Settings.

Posted on 2001-07-26
7
Medium Priority
?
600 Views
Last Modified: 2010-04-04
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...
0
Comment
Question by:mrk_raj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 4

Expert Comment

by:StevenB
ID: 6325769
This might help:



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(ProxyInfo^.lpszProxy, [':']) do try
      Server := NextToken;
      if HasMoreTokens then
        Port := StrToInt(NextToken)
      else
        Port := 0;
    finally
      Free;
    end;
  finally
    FreeMem(Buffer);
  end;
end;
0
 
LVL 3

Accepted Solution

by:
rondi earned 150 total points
ID: 6325878
Use TRegistry.

I think IE's proxy settings are under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet 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\Windows\CurrentVersion\Internet 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,length(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
0
 
LVL 3

Expert Comment

by:rondi
ID: 6325879
Use TRegistry.

I think IE's proxy settings are under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet 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\Windows\CurrentVersion\Internet 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,length(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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6326905
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\Microsoft\Windows\CurrentVersion\Internet Settings',false);
 Edit1.Text :=Reg.ReadString('ProxyServer');
end;

Best regards
Mohammed Nasman
0
 

Author Comment

by:mrk_raj
ID: 6329554

Thank Rondi for sending me the answer & thank you one and all who has sent comments about my quetion.
0
 

Author Comment

by:mrk_raj
ID: 6329558

Thank Rondi for sending me the answer & thank you one and all who has sent comments about my quetion.
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6332593
 ... 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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question