【问题标题】:Is there a way of getting ConnectionStatus from IVpnProfile in a UWP application?有没有办法从 UWP 应用程序中的 IVpnProfile 获取 ConnectionStatus?
【发布时间】:2019-03-22 03:02:15
【问题描述】:

我有以下 WinRT 代码,可以很好地发现活动的 VPN 配置文件:

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());
}

我想检查 ConnectionStatus,但这在 IVpnProfile 界面上不可用。 我尝试添加以下内容无济于事,因为 ConnectionStatus 在具体的 VpnPlugInProfile 和 VpnNativeProfile 类中可用:

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

这只会给出一个 Invalid Handle 错误。

有没有办法从 IVpnProfile 获取 ConnectionStatus?

【问题讨论】:

  • 这听起来不对。 as 成员函数模板要么返回一个有效的接口指针,要么抛出。您得到的确切错误是什么,来自哪里?
  • 抱歉,Invalid Handle 错误发生在周围的 catch 块中,因此抛出
  • 实际上很容易从 IVpnProfile 获取连接状态 - 只需从 Windows.Networking.Vpn.VpnNativeProfile 查询一个新配置文件,为其分配新获取的配置文件名称,然后查询具有 @ 的 VpnNativeProfile2 987654326@。我有 C 代码可以做到这一点,如果有人感兴趣,我会对其进行测试(因为我将其发布为评论而不是回答)。我无法执行的更复杂的任务是获取当前连接到的服务器。
  • 考虑到您尚未在 %userprofile%\AppData\Local\Packages\%fullpackagename%\LocalState 中创建 rasphone.pbk 文件。因为如果你有 - IVpnProfile 可以查询IVpnNativeProfile。该程序设计巧妙,如果您的应用程序 LocalState 中缺少 rasphone.pbk,它只会填写配置文件名称并禁止进一步查询 nativeprofile。上帝保佑微软。然而,我发现这有一些繁重的逆向工程——如果有一个好的文档和好的代码,那将会很有帮助。

标签: uwp vpn c++-winrt


【解决方案1】:

提示:无效句柄错误是 Windows 中的一个错误;它已被修复,并且修复程序已在低级别提供服务(可能针对 RS5 和 19H1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    相关资源
    最近更新 更多