How do I retrieve all RAS connections?

5.4k views Asked by At

I want to get all RAS connections (Dial-up, Broadband, VPN, etc.) as they appear in my "Network Connections" under "Control Panel". There are some solutions here and on the web to do this, but they are all about getting Active (connected) Connections.

How can I do this? How can I get all active and inactive RAS connections? With or without "DotRas".

2

There are 2 answers

0
Jeff Winn On

There is a component as part of the DotRas SDK which handles management of the phone book entries. Keep in mind that there are two phone books in use by Windows, the one in the all users' profile and the current users' profile. So if you're trying to get a list all the entries that you'd see there, you'd need to access both phone books.

using DotRas;

RasPhoneBook pbk = new RasPhoneBook();
pbk.Open(@"C:\PathToYourPhoneBook.pbk");

// NOTE: You can also use RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers) to 
// access the path as defined by the Windows SDK rather than having to hard-code it.

foreach (RasEntry entry in pbk.Entries)
{
    // Do something useful.
}

The above example is rather limited so for more complete examples check the examples included with the SDK.

For a download link to the above mentioned SDK, see the official website at: http://dotras.codeplex.com

Hope that helps!

0
ewwink On

if you want dynamically get all RAS connection without .pbk file "path"

using DotRas;

string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
RasPhoneBook pbk = new RasPhoneBook();
pbk.Open(path);

foreach (RasEntry entry in pbk.Entries)
{
  MessageBox.Show(entry.Name);
}