Partager via


NetworkOperatorTetheringAccessPointConfiguration.IsAuthenticationKindSupportedAsync Méthode

Définition

Récupère de façon asynchrone une valeur indiquant si l’adaptateur Wi-Fi permet de configurer le point d’accès avec un type d’authentification spécifique.

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)

Paramètres

authenticationKind
TetheringWiFiAuthenticationKind

Valeur d’énumération TetheringWiFiAuthenticationKind , spécifiant le type d’authentification à interroger.

Retours

Objet d’opération asynchrone qui, une fois terminé, contient true si le type d’authentification est pris en charge ; sinon, false.

Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 11 Insider Preview (introduit dans 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v19.0)
Fonctionnalités de l’application
wiFiControl

Exemples

L’exemple de code ci-dessous répertorie deux méthodes publiques : pour définir la bande et le type d’authentification pour une connexion de liaison. Il existe également un exemple de méthode privée pour extraire la configuration de connexion actuelle de la connexion Internet active sur l’ordinateur. L’objet de configuration de liaison contient les propriétés de bande et de type d’authentification qui sont définies, et il s’agit du seul paramètre pour l’API ConfigureAccessPointAsync utilisée pour appliquer les modifications.

Dans Main, les premières lignes de code définissent la bande (à l’aide de la valeur de 6 GHz, si elle est disponible). Notez également l’utilisation de la classe ApiInformation pour case activée si un type d’authentification particulier est pris en charge. Après cela, le code définit le type d’authentification. Ce code illustre l’utilisation des valeurs d’énumération de TetheringWiFiBand et TetheringWiFiAuthenticationKind.

Dans les méthodes publiques SetBandForWiFiAccessPointAsync et SetAuthenticationKindForWiFiAccessPointAsync, le code présente les éléments suivants :

  • Extraction de la configuration AP pour la connexion Internet active sur l’ordinateur.
  • Mise à jour des propriétés de bande et de type d’authentification sur l’objet de configuration (NetworkOperatorTetheringAccessPointConfiguration).
  • Application de la configuration mise à jour et retour de la configuration correctement appliquée (ou null en cas de défaillance).
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);
        }
    }
}

S’applique à