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

SergiiMol 1 Reputation point
2021-06-30T10:18:09.33+00:00

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 development | Windows API - Win32
Developer technologies | C++
{count} votes

3 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2021-07-02T06:41:38.583+00:00

    Hi, @SergiiMol
    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.

    0 comments No comments

  2. SergiiMol 1 Reputation point
    2021-07-02T09:08:12.903+00:00

    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.


  3. SergiiMol 1 Reputation point
    2021-07-09T11:26:32+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.