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".
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!
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With