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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Didier VallySystems Engineer and Finance AnalystCommented:
You can use the TJvRas32 component.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.