【问题标题】:WlanHostedNetworkStartUsing or how windows 10 builtin mobile hotspot worksWlan HostedNetwork StartUsing 或 Windows 10 内置移动热点如何工作
【发布时间】:2017-01-24 13:24:53
【问题描述】:

我正在尝试编写一个创建热点的程序。我正在使用WlanHostedNetworkStartUsing,但它返回ERROR_INVALID_STATE。然而,当我调用WlanHostedNetworkInitSettings 时,它返回成功。根据documemtation备注部分的最后一段),它应该在控制面板\网络和互联网\网络和共享中心下创建一个虚拟无线连接,但它没有t.

我搜索了一下,发现了这个:

当我运行 netsh wlan show drivers 时,它会显示:

Driver                    : Intel(R) Dual Band Wireless-AC 3165
Vendor                    : Intel Corporation
Provider                  : Intel
Date                      : 07-Sep-16
Version                   : 19.20.0.6
INF file                  : ????
Type                      : Native Wi-Fi Driver
Radio types supported     : 802.11b 802.11g 802.11n 802.11a 802.11ac
/ ...
Hosted network supported  : No  <--- Here
/ ...

所以它说我的 wifi 适配器根本没有 wifi 共享(我有来自 HP 网站的最后一个驱动程序)。

但是当我尝试使用 Windows 10 内置工具创建热点时它可以工作

问题:windows 工具如何做到这一点,我如何在我的应用程序中使用这种机制?

【问题讨论】:

  • 当你没有发布你的代码时,很难说你做错了什么。
  • 弗拉德。看看这个:github.com/wekillpeople/hotspot-windows/blob/master/wlanhost.c——存储库有你需要的东西,很好的参考!
  • 我已经问过similar question
  • 上述关于“wlanhost.c”的文章仅适用于 Windows 8 之前的旧窗口。之后,它们将 WiFi 替换为“WiFi Direct”api。为此,您需要 WinRT 方法,如下所述。

标签: c++ winapi windows-10 wifi


【解决方案1】:

原始 06/06/2018 cmets 在此处(请参阅下面的更新)

Microsoft 已弃用 WLAN HostedNetwork 功能,它不是 可用于 Win10 驱动程序。要在 Win10 中使用旧模型,您必须 查找并安装 2015 年的驱动程序(8.1 或更早版本,具体取决于 供应商)。

Win10驱动模型将HostedNetwork的机制改为 基于 WiFi Direct,并从应用程序开发人员手中夺走了控制权 将此功能移至内核。如果有一些样品可用 你四处挖掘,展示了如何使用 Modern-com (RT) UWP 应用程序 库来配置 WiFi Direct HostedNetwork。这是一个皮塔饼, 微软没有解释,大多数人不理解 在网络上对此发表评论,这看起来像是一个两步 微软失败,产品功能被削减以进行出货 团队之间的日程安排和重组改变了所有权和计划 WiFi和热点。 WiFi 直接启用 - 理论上 - 更简单 设备之间的配对和身份验证模型。但目前 实施涉及蓝牙,因此值得怀疑 除了支持有限的移动设备 WiFi 2.0 场景。如果你 正在使用无头设备或物联网设备场景这是 坏了。

我不得不在这方面做很多工作。如果您可以选择 WiFi 硬件,我强烈推荐使用 英特尔驱动程序(它们很可靠)。

如果您的场景允许 UX,您可能会发现此 App Store 应用很有帮助 相互作用。 http://www.topuwp.com/windowsapps/wifi-direct-access-point/598084.html

=====================

2020 年 2 月 27 日更新该故事...

Hosted network supported : No 时,legacy 托管网络 支持在您的适配器上不可用,因为您在 Windows 10 等中具有 WiFi Direct。在这种情况下,您需要了解并使用这个很少评论 WiFi Direct 支持的部分:

https://docs.microsoft.com/en-us/uwp/api/windows.networking.networkoperators.networkoperatortetheringmanager.createfromconnectionprofile

HotSpot 设置的命令行:start ms-settings:network-mobilehotspot

有关 PowerShell 以编程方式访问 WinRT HotSpot API 的文章

enable Win10 inbuild hotspot by cmd/batch/powershell

关键词:“虚拟 Wi-Fi”、SoftAP、AdHoc IBSS、MobileHotSpot、netsh wlan HostedNetwork

=====================

如果没有如下有效的C++/WinRT 代码示例,这将是不完整的:

#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Security.Credentials.h>
namespace winrt { // /ZW embed in :<winrt> when `Windows` is ambiguously defined
  static void af_winrt_wifi_hotspot_test() {
    // start ms-settings:network-mobilehotspot
    init_apartment(); // apartment_type::multi_threaded
    if (false /* play as you wish to test this all in simple c++ console app, I used clang */) {
      auto publisher = Windows::Devices::WiFiDirect::WiFiDirectAdvertisementPublisher();
      auto advertisement = publisher.Advertisement();
      advertisement.ListenStateDiscoverability(Windows::Devices::WiFiDirect::WiFiDirectAdvertisementListenStateDiscoverability::Intensive);
      advertisement.IsAutonomousGroupOwnerEnabled(true);
      auto legacySettings = advertisement.LegacySettings();
      legacySettings.IsEnabled(true);
      legacySettings.Ssid(L"your-hotspot-name");
      auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
      legacySettings.Passphrase(credential);
      publisher.Start();
    }
    else {
      auto connectionProfile{ Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };
      auto tetheringManager = Windows::Networking::NetworkOperators::NetworkOperatorTetheringManager::CreateFromConnectionProfile(connectionProfile);
      auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
      auto conf = Windows::Networking::NetworkOperators::NetworkOperatorTetheringAccessPointConfiguration();
      conf.Ssid(L"I-Own-You"); conf.Passphrase(credential.Password());
      auto oldConf = tetheringManager.GetCurrentAccessPointConfiguration();
      auto oldSsid = oldConf.Ssid(); auto oldPwd = oldConf.Passphrase();
      tetheringManager.ConfigureAccessPointAsync(conf); // Sets new ssid/pwd here
      switch (tetheringManager.TetheringOperationalState()) {
      case Windows::Networking::NetworkOperators::TetheringOperationalState::Off: {
        auto ioAsync = tetheringManager.StartTetheringAsync();
        auto fResult = ioAsync.get();
        }                                                                                    
        break;
      case Windows::Networking::NetworkOperators::TetheringOperationalState::On: {
        // auto ioAsync = tetheringManager.StopTetheringAsync();
        // auto fResult = ioAsync.get();
        }                                                                                 
        break;
      case Windows::Networking::NetworkOperators::TetheringOperationalState::InTransition:
      default:
        break;
      }
    }        
    clear_factory_cache();
    uninit_apartment();
  }
}

在此处查找与 WiFiDirectAdvertisementPublisher 相关的旧版 Microsoft 示例:

网络上的文章如此之多,WiFi-Direct 造成的混乱如此之多。

我花了整整两天时间才弄清楚这一切。在我看来,这很多。

微软(我曾在该公司担任架构师)没有理由不创建一个关于这个非常受欢迎的主题的博客。更不用说简单地使 netshAd Hoc Wifi 兼容支持,而不是让开发人员、最终用户和开发人员。

-- 享受 大卫

以上内容非常简洁,并公开了适用于所有场景的工作 c++/WinRT 代码。

[我现在将这个捆绑在 EdgeS 中:EdgeShell/EdgeScript/afm-scm 工具集] []5

【讨论】:

  • 哇。非常感谢您提供解决方案的更新。我同意,WiFi Direct 的文档记录很差,而且我遇到了让非传统 WiFi Direct 行为在 Windows 和 Linux 之间工作的问题。因此,我非常需要一个可靠的解决方案,所以我将回到旧功能。再次感谢。
【解决方案2】:

admin 身份打开命令提示符并尝试以下命令:

netsh wlan set hostednetwork mode=allow ssid=“OSToto Hotspot” key=“12345678”

ssid 是您的网络名称,密钥是密码。您可以像上面的命令一样命名它们。

然后运行:

netsh wlan start hostednetwork

先休息再说,我想通过你的源代码。

【讨论】:

  • 那行不通,因为Hosted network supported : No
  • 这是托管网络,问题是关于移动热点。
【解决方案3】:

您的计算机不支持托管网络。

因此,这是行不通的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2023-04-07
    相关资源
    最近更新 更多