本文介绍了WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试编写一个创建热点的程序.我正在使用 WlanHostedNetworkStartUsing 但它返回 ERROR_INVALID_STATE.然而,当我调用 WlanHostedNetworkInitSettings 时,它返回成功.根据

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

解决方案

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

02/27/2020 Update to that story...

When Hosted network supported : No then legacy hosted network support is not available on your adapter because you have WiFi Direct in Windows 10 etc. In which case you'll want to know and use this very sparsely commented on supported portion of WiFi Direct:

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

Command Line to HotSpot settings: start ms-settings:network-mobilehotspot

Article that talks about PowerShell programmatic access to the WinRT HotSpot APIs

enable Win10 inbuild hotspot by cmd/batch/powershell

KEYWORDS: "Virtual Wi-Fi", SoftAP, AdHoc IBSS, MobileHotSpot, netsh wlan HostedNetwork

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

Which would not be complete without a working C++/WinRT code sample as follows:

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

Look here for older Microsoft Samples relating to WiFiDirectAdvertisementPublisher:

So many articles on the web, so much confusion created by WiFi-Direct.

I've spent two whole days figuring it all out. Which, for my time, is a lot.

No excuse for Microsoft (where I use to work as an Architect) not having created a Blog about this very popular topic. Let alone simply having made netsh and Ad Hoc Wifi compat support, instead of leaving it so cryptic and confusing for devops, end-users, and developers.

-- enjoy David

The above is pretty concise, and exposes working c++/WinRT code for all scenarios.

[I now have this bundled in EdgeS: EdgeShell/EdgeScript/afm-scm toolset][]5

这篇关于WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 05:55