Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Delphi application detect the network proxy settings of a Windows PC?

I have a Delphi application that communicates with web servers on the Internet using the Indy components. Most users of the application have direct Internet connections but some are behind a proxy server of a local network. I don't want to have to ask the users to lookup their proxy server in the Internet Options / Connections / LAN Settings dialog

alt text http://toybase.files.wordpress.com/2008/11/ie-proxy-settings.png

as quite frankly most people won't know or care what this setting is.

Can I get this information via some system calls from a Delphi-7 appplication?

Many thanks!

like image 758
devstopfix Avatar asked Jan 06 '10 15:01

devstopfix


2 Answers

Via WinAPI -- WinHttpGetIEProxyConfigForCurrentUser. You gotta love MS's long WINAPI names ^_^.

After OP edit: You can read from the registry, AFAIR it would be located here :

 [ HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings ]
like image 110
Kornel Kisielewicz Avatar answered Sep 19 '22 16:09

Kornel Kisielewicz


The Delphi code for Kornel Kisielewicz's answer:

uses Registry, Windows;

function detectIEProxyServer() : string;
begin
  with TRegistry.Create do
    try
        RootKey := HKEY_CURRENT_USER;
        if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', False) then begin
          Result := ReadString('ProxyServer');
          CloseKey;
        end
        else
          Result := '';
    finally
      Free;
    end;
end;
like image 28
2 revs Avatar answered Sep 22 '22 16:09

2 revs