Is there a way of getting ConnectionStatus from IVpnProfile in a UWP application?
Asked Answered
S

1

10

I have the following WinRT code which works fine to discover active VPN Profiles:

VpnManagementAgent vpn;
auto profiles = vpn.GetProfilesAsync().get();
wprintf(L"Found %d profiles\n", profiles.Size());
for (auto vp : profiles)
{
    wprintf(L"Found profile %s\n", vp.ProfileName().c_str());
}

I would like to check the ConnectionStatus but this is not available on the IVpnProfile interface. I have tried adding the following to no avail as ConnectionStatus is available in the concrete VpnPlugInProfile and VpnNativeProfile classes:

VpnPlugInProfile pp = vp.as<VpnPlugInProfile>();
if (pp != nullptr)
    wprintf(L"ConnectionStatus = %d\n", pp.ConnectionStatus());

This just give an Invalid Handle error.

Is there a way of getting ConnectionStatus from IVpnProfile?

Sympathin answered 17/10, 2018 at 12:21 Comment(4)
That doesn't sound right. The as member function template either returns a valid interface pointer, or throws. What is the exact error you get, and where from?Transilluminate
Sorry, yes the Invalid Handle error happens in a surrounding catch block so as is throwingSympathin
It's actually quite easy to get the connection status from a IVpnProfile - simply query from Windows.Networking.Vpn.VpnNativeProfile a new profile, assign to it your newly acquired profile name and then query for VpnNativeProfile2 which has a get_ConnectionStatus. I have C code which do it and I tested it if someone is interested (reason I'm posting this as comment and not answer). The more complex task I am unable to perform is acquire the servers to which a connection is currently connected to.Commissariat
That is considering you haven't created a rasphone.pbk file inside your %userprofile%\AppData\Local\Packages\%fullpackagename%\LocalState. Because if you have so - IVpnProfile can be queried for IVpnNativeProfile. The program is designed clever and in case of missing rasphone.pbk inside your app LocalState it'll only fill the profile name and forbid further queries to nativeprofile. God bless Microsoft. However I've found this with some heavy reverse - engineering - it would be helpful if instead there was a good documentation as well as good code.Commissariat
C
0

Hint: the invalid handle error is a bug in Windows; it's been fixed and the fix was serviced down-level (possibly to RS5 and 19H1)

Cobblestone answered 10/7, 2020 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.