Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Internet / LAN / ASP.NET (https://www.delphipraxis.net/23-library-internet-lan-asp-net/)
-   -   Delphi Proxy Server Einstellungen des IE abfragen (https://www.delphipraxis.net/19756-proxy-server-einstellungen-des-ie-abfragen.html)

shmia 8. Apr 2004 10:58


Proxy Server Einstellungen des IE abfragen
 
Hallo,

mit den folgenden Funktionen/Proceduren ist es möglich die Proxy Server Einstellungen
des Internet Explorers abzufragen:

Delphi-Quellcode:
unit IEProxy;

interface

uses WinInet, SysUtils, Windows;

type
  TProtocol = (http,
               https,
               ftp,
               gopher,
               socks);

  TProxyInfo = record
    Servername: ShortString;
    Port     : word;
  end;

function GetProxyServer(protocol: TProtocol; var ProxyServer: string;
         var ProxyPort: word): Boolean; overload;

function GetProxyServer(protocol: TProtocol;
         var ServerInfo: TProxyInfo): Boolean; overload;

implementation

function ProtocolToString(Protocol: TProtocol): string;
begin
  case Protocol of
    http : Result := 'http';
    https : Result := 'https';
    ftp  : Result := 'ftp';
    gopher: Result := 'gopher';
    socks : Result := 'socks';
    else   Result := '';
  end;
end;

function GetProxyInformation:string;
var
  ProxyInfo: PInternetProxyInfo;
  Len: LongWord;
begin
  Result := '';
  Len := 4096;
  GetMem(ProxyInfo, Len);
  try
    if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
      if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
      begin
        Result := ProxyInfo^.lpszProxy
      end;
  finally
    FreeMem(ProxyInfo);
  end;
end;

{**************************************************************************
* NAME:     GetProxyServer
* DESC:     Proxy-Server Einstellungen abfragen
* PARAMS:   protocol => z.B. 'http' oder 'ftp'
* RESULT:   Boolean (Proxy für Protokoll eingetragen)
* CREATED:  08-04-2004/shmia
* MODIFIED: 11-01-2008/DeddyH
*************************************************************************}
function GetProxyServer(protocol: TProtocol; var ProxyServer: string;
         var ProxyPort: word): Boolean;
var
  i : Integer;
  proxyinfo, prot : string;
begin
  Result := false;
  ProxyServer := '';
  ProxyPort  := 0;

  proxyinfo := AnsiLowerCase(GetProxyInformation);
  if proxyinfo = '' then
    Exit;

  prot := ProtocolToString(protocol) + '=';

  i := Pos(prot, proxyinfo);
  if i > 0 then
  begin
    Delete(proxyinfo, 1, i + Pred(Length(prot)));
    i := Pos(';', proxyinfo);
    if i > 0 then
      proxyinfo := Copy(proxyinfo, 1, i-1)
    else
      begin
        i := Pos(#32,proxyinfo);
        if i > 0 then
          proxyinfo := Copy(proxyinfo, 1, i-1);
      end;
    Result := true;
  end;

  i := Pos(':', proxyinfo);
  if i > 0 then
    begin
      ProxyPort := StrToIntDef(Copy(proxyinfo, i+1, Length(proxyinfo)-i), 0);
      ProxyServer := Copy(proxyinfo, 1, i-1);
      Result := true;
    end;
end;

function GetProxyServer(protocol: TProtocol; var ServerInfo: TProxyInfo): Boolean;
var s: string;
    i: word;
begin
  Result := GetProxyServer(protocol,s,i);
  ServerInfo.Servername := s;
  ServerInfo.Port := i;
end;

end.
[edit=Matze]Code formatiert. Mfg, Matze[/edit]
[edit=Matze]Überarbeiteten und erweiterten Source-Code von DeddyH eingefügt. MfG, Matze[/edit]
[edit=Matze]Ein "Result" ergänzt. MfG, Matze[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz