共用方式為


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

範例

下列程式碼範例列出兩個公用方法:用於設定頻寬和連線連線的驗證種類。 另外還有一個範例私用方法,用於擷取電腦上作用中網際網路連線的目前網路連線組態。 連線組態物件包含所設定的頻外和驗證種類屬性,而它是用來套用變更之 ConfigureAccessPointAsync API 的唯一參數。

Main中,如果可以使用 6 GHz 值,則前幾行程式碼會使用 6 GHz 值來設定帶) (。 另請注意,使用 ApiInformation 類別來檢查是否支援特定驗證種類。 之後,程式碼會設定驗證種類。 此程式碼示範如何使用 TetheringWiFiBandTetheringWiFiAuthenticationKind的列舉值。

公用方法 SetBandForWiFiAccessPointAsyncSetAuthenticationKindForWiFiAccessPointAsync中,程式碼會展示下列專案:

  • 擷取電腦上作用中網際網路連線的 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);
        }
    }
}

適用於