Get active connection name and set proxy auto config url - Delphi7

Hi friends,
I need to set IE to use proxy fom a proxy auto-config file. With the code above im able to set it on LAN but on dial up connection only works if i set the active connection name. I think that if i could get the active connection name and set the result into 'list.pszConnection :=' it will work right?
I need some help with this. Make it work setting proxy auto-config file(proxy.pac) under lan AND dial up connection.

Thanks.
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;

implementation

{$R *.dfm}
const
 INTERNET_PER_CONN_FLAGS = 1;
 INTERNET_PER_CONN_PROXY_SERVER = 2;
 INTERNET_PER_CONN_PROXY_BYPASS = 3;
 INTERNET_PER_CONN_AUTOCONFIG_URL = 4;
 INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5;
 PROXY_TYPE_DIRECT = $00000001; 
 PROXY_TYPE_PROXY = $00000002; 
 PROXY_TYPE_AUTO_PROXY_URL = $00000004; 
 PROXY_TYPE_AUTO_DETECT = $00000008; 
 INTERNET_OPTION_REFRESH = 37;
 INTERNET_OPTION_PER_CONNECTION_OPTION = 75;
 INTERNET_OPTION_SETTINGS_CHANGED = 39;
 

 
//--TProxy Section--------------------------------------------------------------
type
   INTERNET_PER_CONN_OPTION = record
      dwOption: DWORD;
      Value: record
         case Integer of
            1: (dwValue: DWORD);
            2: (pszValue: PAnsiChar);
            3: (ftValue: TFileTime);
      end;
   end;
LPINTERNET_PER_CONN_OPTION = ^INTERNET_PER_CONN_OPTION;
INTERNET_PER_CONN_OPTION_LIST = record
  dwSize: DWORD;
  pszConnection: LPTSTR;
  dwOptionCount: DWORD;
  dwOptionError: DWORD;
  pOptions: LPINTERNET_PER_CONN_OPTION;
end;
    //  -------------------------
function SetProxy(UserAgent, PacFile: PChar): Boolean;
var
  list: INTERNET_PER_CONN_OPTION_LIST;
  dwBufSize: DWORD;
  hInternet: Pointer;
  Options: array[1..2] of INTERNET_PER_CONN_OPTION;
begin
  Result := False;
  dwBufSize := SizeOf(list);
  list.dwSize := SizeOf(list);
 // list.pszConnection := ''; //name of connection
  list.pszConnection := nil;
  list.dwOptionCount := High(Options);
  Options[1].dwOption := INTERNET_PER_CONN_AUTOCONFIG_URL;
  Options[1].Value.pszValue := PacFile;
  Options[2].dwOption := INTERNET_PER_CONN_FLAGS;
  Options[2].Value.dwValue := PROXY_TYPE_AUTO_PROXY_URL;
  list.dwOptionCount := 2;
  list.dwOptionError := 0;
  list.pOptions := @Options;
  hInternet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
  if hInternet <> nil then
  try
    Result := InternetSetOption(hInternet, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize);
    Result := InternetSetOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize);
    Result := Result and InternetSetOption(hInternet, INTERNET_OPTION_REFRESH, nil, 0);
  finally
    InternetCloseHandle(hInternet)
  end;
end;




procedure TForm1.Button1Click(Sender: TObject);
begin
SetProxy('', 'http://www.myhost.com/proxy.pac');
end;
end.

Open in new window

voxzaumAsked:
Who is Participating?
 
Didier VallySystems Engineer and Finance AnalystCommented:
You can use the TJvRas32 component.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.