Hi, all.
I need to get list of the available VPN connections on PC (Windows 10) using console app on C++ 17 and how can I change param AllUserConnection of all of this available VPN connections?
Hi, all.
I need to get list of the available VPN connections on PC (Windows 10) using console app on C++ 17 and how can I change param AllUserConnection of all of this available VPN connections?
As far as I'm concerned, there is no suitable winapi to get the list of available VPN connections on the PC (Windows 10) using console app on C++ 17. And I suggest you could try to use the powershell to realize it.
I suggest you could refer to the following Doc:
Get-VpnConnection
Set-VpnConnection
Command "Get-VpnConnection" shows VPN connections only for current user (not for all users!) => if VPN connection has paramete "AllUserConnection" equal "true", than it wouldn't returned.
Command Get-VpnConnection -Name "Test1" works in the same way! (if VPN connection "Test1" has paramete "AllUserConnection" equal "true", than it wouldn't returned)
Similar situation with command Set-VpnConnection.
I've found WinAPI function RasEnumEntries (in Ras.h) and use it for getting the list of VPN connections (it works), but then I've got error ERROR_CANNOT_FIND_PHONEBOOK_ENTRY when I use RasGetEntryProperties (to get properties of my VPN connections)
After successfully enumerating the entries does the code pass the full path to the phone book that is returned in the RASENTRYNAME structs obtained from the enumeration as the first parameter to RasGetEntryProperties?
Hi, @SergiiMol-1132
I found a Microsoft Github Sample which enumerates the RAS phone-book entries and gets properties of each entry using RasEnumEntries and RasGetEntryProperties.
Wish It’s helpful.
Hi,
Function RasEnumEntries returns the list of VPN connections with struct LPRASENTRYNAME, in this struct is parameter dwFlags ("Specifies whether the entry is in the system phone book in the AllUsers profile, or in the user's profile phone book"). But I can't find how I can change dwFlags this for each VPN connection.
Have you tried RasSetEntryPropertiesA? The Sample has set the dwfOptions2 property successfully.
According to RasDialDlgW, you can edit the exiting or create a new Entry properties by RasEntryDlgW, RasPhonebookDlgW Or Tools which setup or edit the phone-book (PBK) file as required.
The following picture shows RasEntryDlgW example result.

I will answer my own questions :) (maybe it will be useful to someone):
1) A list of all available VPN connections on the current PC can be obtained using function RasEnumEntries and the returned list contains the parameter "dwFlags", which shows this connection common for all users (= REN_AllUsers) or personally for some one user (= REN_User).
2) The parameter "AllUserConnection" for existing VPN connections cannot be changed using WinAPI. But, I have found one way to do it: in the list from item 1), there is a parameter szPhonebookPath - this is the path to a file in the system where stored the data about VPN connections. You can transfer data from the general VPN connections file (default path C: \ ProgramData \ Microsoft \ Network \ Connections \ Pbk \ rasphone.pbk) to the VPN connections file for specific users (default path C: \ Users \ <username> \ AppData \ Roaming \ Microsoft \ Network \ Connections \ Pbk \ rasphone.pbk). But you need to take into account different options: don't duplicate connections; enumerate users who need to add connections; etc.
8 people are following this question.