Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve all RAS connections?

Tags:

c#

ras

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".

like image 259
h.nodehi Avatar asked Jan 25 '12 15:01

h.nodehi


2 Answers

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!

like image 137
Jeff Winn Avatar answered Nov 07 '22 18:11

Jeff Winn


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);
}
like image 2
ewwink Avatar answered Nov 07 '22 18:11

ewwink