NetworkOperatorTetheringAccessPointConfiguration.IsAuthenticationKindSupportedAsync 方法

定义

异步检索一个值,该值指示 Wi-Fi 适配器是否允许使用特定身份验证类型配置接入点。

public:
 virtual IAsyncOperation<bool> ^ IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind authenticationKind) = IsAuthenticationKindSupportedAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<bool> IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind const& authenticationKind);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<bool> IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind authenticationKind);
function isAuthenticationKindSupportedAsync(authenticationKind)
Public Function IsAuthenticationKindSupportedAsync (authenticationKind As TetheringWiFiAuthenticationKind) As IAsyncOperation(Of Boolean)

参数

authenticationKind
TetheringWiFiAuthenticationKind

TetheringWiFiAuthenticationKind 枚举值,指定要查询的身份验证类型。

返回

异步操作对象完成时包含 true 身份验证类型是否受支持,否则为 false

属性

Windows 要求

设备系列
Windows 11, version 24H2 (在 10.0.26100.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v19.0 中引入)
应用功能
wiFiControl

示例

下面的代码示例列出了两种公共方法:用于设置连接连接的带和身份验证类型。 还有一个示例专用方法,用于提取计算机上活动 Internet 连接的当前网络连接配置。 连接配置对象包含正在设置的带和身份验证类型属性,它是用于应用更改的 ConfigureAccessPointAsync API 的唯一参数。

Main 中,前几行代码使用 6 GHz 值设置带 ((如果可用) )。 另请注意,使用 ApiInformation 类检查是否支持特定的身份验证类型。 之后,代码将设置身份验证类型。 此代码演示如何使用 TetheringWiFiBandTetheringWiFiAuthenticationKind 中的枚举值。

在公共方法 SetBandForWiFiAccessPointAsyncSetAuthenticationKindForWiFiAccessPointAsync 中,代码显示以下内容:

  • 提取计算机上活动 Internet 连接的 AP 配置。
  • 更新配置对象上的带和身份验证类型属性 (NetworkOperatorTetheringAccessPointConfiguration) 。
  • 应用更新的配置,并在 (或在 null 发生故障) 的情况下返回成功应用的配置。
using System;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.Networking.NetworkOperators;
using Windows.Networking.Connectivity;

namespace DemoApp
{
    class DemoClass
    {
        private static NetworkOperatorTetheringAccessPointConfiguration GetCurrentAPConfig()
        {
            // Get the connection profile associated with the internet connection currently used by the local machine.
            ConnectionProfile currentConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
            if (currentConnectionProfile == null)
            {
                throw new InvalidOperationException("Machine isn't connected to the internet.");
            }

            NetworkOperatorTetheringManager tetheringManager =
                NetworkOperatorTetheringManager.CreateFromConnectionProfile(currentConnectionProfile);

            NetworkOperatorTetheringAccessPointConfiguration configuration =
                tetheringManager.GetCurrentAccessPointConfiguration();

            return configuration;
        }

        public static async Task<NetworkOperatorTetheringAccessPointConfiguration>
            SetBandForWiFiAccessPointAsync(TetheringWiFiBand wifiBand)
        {
            NetworkOperatorTetheringAccessPointConfiguration configuration = GetCurrentAPConfig();

            if (!await configuration.IsBandSupportedAsync(wifiBand))
            {
                throw new ArgumentException("Band parameter isn't supported on AP.");
            }

            configuration.Band = wifiBand;

            try
            {
                await tetheringManager.ConfigureAccessPointAsync(configuration);

                return configuration;
            }
            catch
            {
                return null;
            }
        }

        public static async Task<NetworkOperatorTetheringAccessPointConfiguration>
            SetAuthenticationKindForWiFiAccessPointAsync(TetheringWiFiAuthenticationKind wiFiAuthenticationKind)
        {
            if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 16))
            {
                throw new InvalidOperationException("OS doesn't support configuring auth.");
            }

            NetworkOperatorTetheringAccessPointConfiguration configuration = GetCurrentAPConfig();

            if (!await configuration.IsAuthenticationKindSupportedAsync(wiFiAuthenticationKind))
            {
                throw new ArgumentException("Authentication kind parameter isn't supported on AP.");
            }

            configuration.AuthenticationKind = wiFiAuthenticationKind;

            try
            {
                await tetheringManager.ConfigureAccessPointAsync(configuration);

                return configuration;
            }
            catch
            {
                return null;
            }
        }

        public static void Main()
        {
            NetworkOperatorTetheringAccessPointConfiguration sampleResult1 = null;
            if (ApiInformation.IsEnumNamedValuePresent(
                "Windows.Networking.NetworkOperators.TetheringWiFiBand", "SixGigahertz"))
            {
                sampleResult1 = await SetBandForWiFiAccessPointAsync(TetheringWiFiBand.SixGigahertz);
            }
            else
            {
                sampleResult1 = await SetBandForWiFiAccessPointAsync(TetheringWiFiBand.FiveGigahertz);
            }

            NetworkOperatorTetheringAccessPointConfiguration sampleResult2 =
                await SetAuthenticationKindForWiFiAccessPointAsync(TetheringWiFiAuthenticationKind.Wpa3);
        }
    }
}

适用于