Share via


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 Insider Preview (10.0.26100.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v19.0 で導入)
アプリの機能
wiFiControl

次のコード例では、2 つのパブリックメソッドを示します。テザリング接続のバンドと認証の種類を設定します。 マシン上のアクティブなインターネット接続の現在のテザリング構成をフェッチするためのプライベート メソッドの例もあります。 テザリング構成オブジェクトには、設定されているバンドと認証の種類のプロパティが含まれており、変更の適用に使用される ConfigureAccessPointAsync API の唯一のパラメーターです。

Main では、コードの最初の数行でバンドが設定されます (使用可能な場合は 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);
        }
    }
}

適用対象