question

SergiiMol-1132 avatar image
0 Votes"
SergiiMol-1132 asked SergiiMol-1132 answered

C++. The list of the available VPN connections on PC

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?

windows-apic++
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SergiiMol-1132

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


0 Votes 0 ·

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)

0 Votes 0 ·

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?

0 Votes 0 ·
Show more comments
XiaopoYang-MSFT avatar image
0 Votes"
XiaopoYang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SergiiMol-1132 avatar image
0 Votes"
SergiiMol-1132 answered SergiiMol-1132 commented

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.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Have you tried RasSetEntryPropertiesA? The Sample has set the dwfOptions2 property successfully.

0 Votes 0 ·

I did not find any suitable parameter there

0 Votes 0 ·

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.

111695-image.png


0 Votes 0 ·
image.png (22.2 KiB)
Show more comments
SergiiMol-1132 avatar image
0 Votes"
SergiiMol-1132 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.