Freigeben über


NetworkOperatorTetheringAccessPointConfiguration.IsAuthenticationKindSupportedAsync Methode

Definition

Ruft asynchron einen Wert ab, der angibt, ob der Wi-Fi Adapter die Konfiguration des Zugriffspunkts mit einer bestimmten Authentifizierungsart zulässt.

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)

Parameter

authenticationKind
TetheringWiFiAuthenticationKind

Ein TetheringWiFiAuthenticationKind-Enumerationswert , der die Authentifizierungsart angibt, zu der abfragen werden soll.

Gibt zurück

Ein asynchrones Vorgangsobjekt, das nach Abschluss enthält true , ob die Authentifizierungsart unterstützt wird, falseandernfalls .

Attribute

Windows-Anforderungen

Gerätefamilie
Windows 11 Insider Preview (eingeführt in 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v19.0)
App-Funktionen
wiFiControl

Beispiele

Im folgenden Codebeispiel werden zwei öffentliche Methoden aufgeführt: zum Festlegen des Bandes und der Authentifizierungsart für eine Tetheringverbindung. Es gibt auch eine private Beispielmethode zum Abrufen der aktuellen Tetheringkonfiguration der aktiven Internetverbindung auf dem Computer. Das Tetheringkonfigurationsobjekt enthält die Eigenschaften band und Authentifizierungsart, die festgelegt werden, und es ist der einzige Parameter für die ConfigureAccessPointAsync-API , die zum Anwenden der Änderungen verwendet wird.

In Main legen die ersten Codezeilen das Band fest (unter Verwendung des 6-GHz-Werts, sofern verfügbar). Beachten Sie auch die Verwendung der ApiInformation-Klasse , um zu überprüfen, ob eine bestimmte Authentifizierungsart unterstützt wird. Danach legt der Code die Authentifizierungsart fest. Dieser Code veranschaulicht die Verwendung von Enumerationswerten aus TetheringWiFiBand und TetheringWiFiAuthenticationKind.

In den öffentlichen Methoden SetBandForWiFiAccessPointAsync und SetAuthenticationKindForWiFiAccessPointAsync zeigt der Code Folgendes:

  • Abrufen der AP-Konfiguration für die aktive Internetverbindung auf dem Computer.
  • Aktualisieren der Band- und Authentifizierungsarteigenschaften für das Konfigurationsobjekt (NetworkOperatorTetheringAccessPointConfiguration).
  • Anwenden der aktualisierten Konfiguration und Zurückgeben der erfolgreich angewendeten Konfiguration (oder null im Falle eines Fehlers).
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);
        }
    }
}

Gilt für: