Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Proxy-Einstellungen automatisch ermitteln (https://www.delphipraxis.net/95223-proxy-einstellungen-automatisch-ermitteln.html)

Blink 3. Jul 2007 14:09


Proxy-Einstellungen automatisch ermitteln
 
Hi

Wie kann ich die Proxy-Einstellungen des Internet Explorers/ von Windows ermittel? Damit ich sie für die Komponente TIdHTTP verwenden kann. Ich hab schon vergeblich versucht mit Google was zu finden, hab aber leider nichts richtiges finden können.

In der Code-Library hab ich das HIER gefunden, nur bekomme ich einen Leeren String zurück wenn ich die Fubtion GetProxyInformation aufrufe.

ach ja ich verwende Indy 10, falls das weiter helfen solte.

ascotlx 3. Jul 2007 14:34

Re: Proxy-Einstellungen automatisch ermitteln
 
Liste der Anhänge anzeigen (Anzahl: 1)
Moin Blink,

bei mir gibt es mit folgendem Code eine richtige Ausgabe ....

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, WinInet;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  ProxyPort: string;
  ProxyServer: string;

implementation

{$R *.dfm}

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: [-]
* CREATED: 08-04-2004/shmia
*************************************************************************}
procedure GetProxyServer(protocol:string; var ProxyServer:string; var ProxyPort:Integer);
var
  i : Integer;
  proxyinfo, ps : string;
begin
  ProxyServer := '';
  ProxyPort  := 0;

  proxyinfo := GetProxyInformation;
  if proxyinfo = '' then
    Exit;

  protocol := protocol+'=';

  i := Pos(protocol, proxyinfo);
  if i > 0 then
  begin
    Delete(proxyinfo, 1, i+Length(protocol));
    i := Pos(';', ProxyServer);
    if i > 0 then
      proxyinfo := Copy(proxyinfo, 1, i-1);
  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)
  end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Label1.Caption:=GetProxyInformation;
end;

end.
Das ist der gleiche Code wie in Deinem Link ... hast Du eine Fehlermeldung o.ä. ??

gruss ascotlx

EDIT EDIT EDIT
Ich arbeite mit Win2000 und einem IE6. Anhand des Bildes kannst Du sehen was/wo bei mir eingetragen ist.

cu

ascotlx 3. Jul 2007 15:56

Re: Proxy-Einstellungen automatisch ermitteln
 
... und noch was...

der Kram steht anscheinend auch in der Registry unter ...

HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Internet Settings
und der ProxyServer-Schlüssel lautet:
"ProxyServer"="http://proxy:8080"

....

Blink 3. Jul 2007 15:59

Re: Proxy-Einstellungen automatisch ermitteln
 
Danke dir ascotlx, werde ich gleich mal so ausprobieren, nein ich bekomme keine Fehlermeldung, nur ein leeren String.

shmia 3. Jul 2007 17:30

Re: Proxy-Einstellungen automatisch ermitteln
 
Die Stringverarbeitung innerhalb von GetProxyServer() ist noch etwas mangelhaft.
Was liefert denn die Funktion GetProxyInformation() zurück?

Blink 3. Jul 2007 22:40

Re: Proxy-Einstellungen automatisch ermitteln
 
ich hab es Jetzt noch mal Versucht und weder bei GetProxyInformation noch bei GetProxyServer() hat es Funktioniert. Bekomme einen Leeren String zurück, also ohne irgendwas drin hab es so gemacht wie ascotlx. Gibt es eine andere möglichkeit die Prox-Informationen zu bekommen ich hab HIER noch was gefunden, hab es aber nicht ganz Verstanden, was ist das für eine Variable MY oder ist das Delphi für Net die er benutzt hat?

oki 4. Jul 2007 07:34

Re: Proxy-Einstellungen automatisch ermitteln
 
Hi,

offensichtlich sind die Einstellungen in einer Klasse als Eigenschaften hinterlegt und diese wurde mit der Variablen MY instanziiert. So erfolgt der Zugriff einfach nur über das Object My.Eigenschaft.

Gruß oki

Blink 4. Jul 2007 09:33

Re: Proxy-Einstellungen automatisch ermitteln
 
Hi

So, ich hab jetzt raus gefunden warum es bei mir nicht geklappt hatte mit GetProxyInformation, he he ich blöd man :wall: hab die Proxy-Daten an der Falschen stelle eingegeben. Jetzt Funktioniert es und ich bekomme keinen Leeren String mehr zurück.

Danke noch mal an alle die versucht haben zu Helfen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:08 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