How to get all RAS connections?

I want to get all RAS connections (Dial-up, Broadband, VPN, etc.) as they appear in my "Network Connections" in the "Control Panel" section. There are several solutions for this on the Internet, but they are all related to getting Active (connected) connections .

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

+4
source share
2 answers

The DotRas SDK has a component that handles the management of phone book entries. Keep in mind that Windows uses two phone books, one of which concerns the profile of all users and the profile of current users. Therefore, if you are trying to get a list of all the entries that you see there, you will need to access both 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 pretty limited, so check out the examples included in the SDK for more complete examples.

To download links to the aforementioned SDK, see the official website at: http://dotras.codeplex.com

Hope this helps!

+4
source

if you want to dynamically get all RAS connections without a .pbk path file

 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); } 
+1
source

Source: https://habr.com/ru/post/1392962/


All Articles