Einzelnen Beitrag anzeigen

smt

Registriert seit: 29. Okt 2007
15 Beiträge
 
#7

Re: TMozillaBrowser und Proxy

  Alt 8. Aug 2008, 07:57
Also ich hab das folgendermassen gelöst:


Delphi-Quellcode:
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;
und dann irgendwo später:

Delphi-Quellcode:
 with TRegistry.Create do
    try
      RootKey := HKEY_CURRENT_USER;
      OpenKey('\Software\Microsoft\Windows\CurrentVersion\' +
        'Explorer\Shell Folders', True);
        speicher_pfad:=ReadString('AppData');
    finally
      CloseKey;
      Free;
    end;

    getproxyserver('http',server,port);

    speicher_pfad :=speicher_pfad + '\MozillaControl\profiles\MozillaControl\';
    doserror:=Findfirst(speicher_pfad + '*.*',faDirectory,dt);
    WHILE doserror = 0 DO BEGIN
       IF (dt.name <> '.') and (dt.name <> '..') Then speicher_pfad:=speicher_pfad + dt.Name + '\';
       doserror:=Findnext(dt);
    END;

    // Hier die User-Prefs anlegen
    IF server <> 'THEN BEGIN
       ASSIGNFILE(datei,speicher_pfad + 'user.js');
       REWRITE(datei);
       Writeln(datei,'user_pref("network.proxy.http", "' + server + '");');
       Writeln(datei,'user_pref("network.proxy.http_port", ' + INTTOSTR(port) + ');');
       Writeln(datei,'user_pref("network.proxy.type", 1);');
       CLOSEFILE(datei);
    END ELSE IF FileExists(speicher_pfad + 'user.js') THEN deletefile(speicher_pfad + 'user.js');
also so hab ich es hinbekommen... wie gesagt, nicht besonders schön, aber es funktioniert.
Natürlich ist das einfache weglöschen der user.js wenn kein proxy mehr eingetragen ist nicht die feine englische art. Für die Anwendung, für die ich es benötigt hatte, reicht es aber aus. Deshalb diese Quick und Dirty Methode. Die Proxy-Einstellungen holt sich das Programm im übrigen aus den IE-Proxy Einstellungen. Aber das kann man ja machen wie man will.


VG Sascha
  Mit Zitat antworten Zitat