1

Earlier I ask how can I set Internet Proxy in Windows connection.

But my problem is that if I want to set all connections, then must be list connection names list. I search over net but I can't find any answer for this.

Community
  • 1
  • 1
Amin
  • 1,242
  • 2
  • 12
  • 25

1 Answers1

2

You're looking for RasEnumEntries function. Delphi doesn't have RAS API functions declared, but easy if you've got JVCL. The TJvRas32 component has a PhoneBook TStrings property in which available connections are populated.

Below is D2007 test code (no error checking):

const
  RAS_MaxEntryName = 256;
  RASBASE = 600;
  ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
  ERROR_INVALID_SIZE = RASBASE + 32;

type
  PRasEntryName = ^TRasEntryName;
  TRasEntryName = record
    dwSize: Longint;
    szEntryName: array [0..RAS_MaxEntryName] of Char;
  end;

function RasEnumEntriesA(reserved: PChar; lpszPhonebook: PChar;
          lpRasEntryName: PRasEntryName; var lpcb: DWORD;
          var lpcEntries: DWORD): DWORD; stdcall; external 'RASAPI32.DLL';

procedure GetRasEntries(List: TStrings);
var
  RasEntryNames: array of TRasEntryName;
  Err, Size, Entries: DWORD;
  i: Integer;
begin
  List.Clear;
  SetLength(RasEntryNames, 1);
  Size := SizeOf(TRasEntryName);
  RasEntryNames[0].dwSize := Size;
  Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
  if (Err = ERROR_BUFFER_TOO_SMALL) and (Entries > 0) then begin
    Assert(Size = SizeOf(TRasEntryName) * Entries);
    SetLength(RasEntryNames, Entries);
    Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
    if Err = 0 then
      for i := 0 to Length(RasEntryNames) do
        List.Add(RasEntryNames[i].szEntryName);
  end else
    List.Add(RasEntryNames[0].szEntryName);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  GetRasEntries(ListBox1.Items);
end;
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • IIRC, RAS is related to dial-up (modem) connections (thus the name `PhoneBook`), and has nothing to do with most of today's Internet access methods where a proxy would most likely apply. – Ken White Mar 02 '11 at 18:22
  • @Ken - It enumerates that's all there's in the connection list of the internet properties: direct connection, dial up to internet/private network, broadband, VPN. If that was not the question then I misunderstood it. – Sertac Akyuz Mar 02 '11 at 18:34
  • thanks for the clarification. I wasn't aware it worked for anything else but dialup (I remember it from years ago, and haven't looked at it since). Thanks for the clarification. – Ken White Mar 02 '11 at 20:37