How do I retrieve all RAS connections?
Asked Answered
P

2

5

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

Pose answered 25/1, 2012 at 15:4 Comment(0)
V
5

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!

Villeinage answered 28/5, 2012 at 16:29 Comment(0)
I
2

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);
}
Igniter answered 2/5, 2013 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.