Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#1

Proxy Server Einstellungen des IE abfragen

  Alt 8. Apr 2004, 10:58
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]
Andreas
  Mit Zitat antworten Zitat