Share via


Funzione WlanGetProfileList (wlanapi.h)

La funzione WlanGetProfileList recupera l'elenco di profili in ordine di preferenza.

Sintassi

DWORD WlanGetProfileList(
  [in]  HANDLE                  hClientHandle,
  [in]  const GUID              *pInterfaceGuid,
  [in]  PVOID                   pReserved,
  [out] PWLAN_PROFILE_INFO_LIST *ppProfileList
);

Parametri

[in] hClientHandle

Handle di sessione del client ottenuto da una chiamata precedente alla funzione WlanOpenHandle .

[in] pInterfaceGuid

GUID dell'interfaccia wireless.

È possibile recuperare un elenco dei GUID per le interfacce wireless nel computer locale usando la funzione WlanEnumInterfaces .

[in] pReserved

Riservato per utilizzi futuri. Deve essere impostato su NULL.

[out] ppProfileList

Struttura PWLAN_PROFILE_INFO_LIST contenente l'elenco di informazioni sul profilo.

Valore restituito

Se la funzione ha esito positivo, il valore restituito è ERROR_SUCCESS.

Se la funzione ha esito negativo, il valore restituito può essere uno dei codici restituiti seguenti.

Codice restituito Descrizione
ERROR_INVALID_HANDLE
L'handle hClientHandle non è stato trovato nella tabella handle.
ERROR_INVALID_PARAMETER
Un parametro non è corretto. Questo errore viene restituito se si verificano una delle condizioni seguenti:
  • hClientHandle è NULL.
  • pInterfaceGuid è NULL.
  • ppProfileList è NULL.
  • pReserved non è NULL.
ERROR_NOT_ENOUGH_MEMORY
Memoria insufficiente per elaborare questa richiesta e allocare memoria per i risultati della query.
RPC_STATUS
Vari codici di errore.

Commenti

La funzione WlanGetProfileList restituisce solo le informazioni di base sui profili wireless in un'interfaccia wireless. L'elenco dei profili wireless in un'interfaccia wireless viene recuperato nell'ordine delle preferenze. WlanSetProfilePosition può essere usato per modificare l'ordine di preferenza per i profili wireless in un'interfaccia wireless.

È possibile recuperare informazioni più dettagliate per un profilo wireless in un'interfaccia wireless usando la funzione WlanGetProfile . La funzione WlanGetProfileCustomUserData può essere usata per recuperare dati utente personalizzati per un profilo wireless in un'interfaccia wireless. È possibile recuperare un elenco delle interfacce wireless e dei GUID associati nel computer locale usando la funzione WlanEnumInterfaces .

La funzione WlanGetProfileList alloca memoria per l'elenco di profili restituiti nel buffer a cui fa riferimento il parametro ppProfileList . Il chiamante è responsabile della liberazione di questa memoria usando la funzione WlanFreeMemory quando questo buffer non è più necessario.

Windows XP con SP3 e API LAN wireless per Windows XP con SP2: I profili guest, i profili con l'autenticazione WPS (Wireless Provisioning Service) e i profili con Wi-Fi Autenticazione protetta Access-None (WPA-None) non sono supportati. Questi tipi di profili non vengono restituiti da WlanGetProfileList, anche se viene visualizzato un profilo di questo tipo nell'elenco dei profili preferito.

Esempio

Nell'esempio seguente vengono enumerate le interfacce LAN wireless nel computer locale, viene recuperato l'elenco di profili in ogni interfaccia LAN wireless e vengono stampati i valoridell'WLAN_PROFILE_INFO_LIST recuperati che contengono le voci WLAN_PROFILE_INFO.

Nota Questo esempio non riuscirà a caricare in Windows Server 2008 e Windows Server 2008 R2 se il servizio LAN wireless non è installato e avviato.
 
#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>

#include <stdio.h>
#include <stdlib.h>

// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")


int wmain()
{

    // Declare and initialize variables.

    HANDLE hClient = NULL;
    DWORD dwMaxClient = 2;      //    
    DWORD dwCurVersion = 0;
    DWORD dwResult = 0;
    DWORD dwRetVal = 0;
    int iRet = 0;
    
    WCHAR GuidString[39] = {0};

    unsigned int i, j;

    /* variables used for WlanEnumInterfaces  */

    PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
    PWLAN_INTERFACE_INFO pIfInfo = NULL;

    PWLAN_PROFILE_INFO_LIST pProfileList = NULL;
    PWLAN_PROFILE_INFO pProfile = NULL;

    dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
    if (dwResult != ERROR_SUCCESS) {
        wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
        return 1;
        // You can use FormatMessage here to find out why the function failed
    }

    dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
    if (dwResult != ERROR_SUCCESS) {
        wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
        return 1;
        // You can use FormatMessage here to find out why the function failed
    } else {
        wprintf(L"WLAN_INTERFACE_INFO_LIST for this system\n");

        wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
        wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
        for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
            pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
            wprintf(L"  Interface Index[%u]:\t %lu\n", i, i);
            iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 
                sizeof(GuidString)/sizeof(*GuidString)); 
            // For c rather than C++ source code, the above line needs to be
            // iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 
            //     sizeof(GuidString)/sizeof(*GuidString)); 
            if (iRet == 0)
                wprintf(L"StringFromGUID2 failed\n");
            else {
                wprintf(L"  Interface GUID[%d]: %ws\n",i, GuidString);
            }    
            wprintf(L"  Interface Description[%d]: %ws", i, 
                pIfInfo->strInterfaceDescription);
            wprintf(L"\n");
            wprintf(L"  Interface State[%d]:\t ", i);
            switch (pIfInfo->isState) {
            case wlan_interface_state_not_ready:
                wprintf(L"Not ready\n");
                break;
            case wlan_interface_state_connected:
                wprintf(L"Connected\n");
                break;
            case wlan_interface_state_ad_hoc_network_formed:
                wprintf(L"First node in a ad hoc network\n");
                break;
            case wlan_interface_state_disconnecting:
                wprintf(L"Disconnecting\n");
                break;
            case wlan_interface_state_disconnected:
                wprintf(L"Not connected\n");
                break;
            case wlan_interface_state_associating:
                wprintf(L"Attempting to associate with a network\n");
                break;
            case wlan_interface_state_discovering:
                wprintf(L"Auto configuration is discovering settings for the network\n");
                break;
            case wlan_interface_state_authenticating:
                wprintf(L"In process of authenticating\n");
                break;
            default:
                wprintf(L"Unknown state %ld\n", pIfInfo->isState);
                break;
            }
            wprintf(L"\n");

            dwResult = WlanGetProfileList(hClient,
                                             &pIfInfo->InterfaceGuid,
                                             NULL, 
                                             &pProfileList);

            if (dwResult != ERROR_SUCCESS) {
                wprintf(L"WlanGetProfileList failed with error: %u\n",
                        dwResult);
                dwRetVal = 1;
                // You can use FormatMessage to find out why the function failed
            } else {
                wprintf(L"WLAN_PROFILE_INFO_LIST for this interface\n");

                wprintf(L"  Num Entries: %lu\n\n", pProfileList->dwNumberOfItems);

                for (j = 0; j < pProfileList->dwNumberOfItems; j++) {
                    pProfile =
                        (WLAN_PROFILE_INFO *) & pProfileList->ProfileInfo[j];

                    wprintf(L"  Profile Name[%u]:  %ws\n", j, pProfile->strProfileName);
                    
                    wprintf(L"  Flags[%u]:\t    0x%x", j, pProfile->dwFlags);
                    if (pProfile->dwFlags & WLAN_PROFILE_GROUP_POLICY)
                        wprintf(L"   Group Policy");
                    if (pProfile->dwFlags & WLAN_PROFILE_USER)
                        wprintf(L"   Per User Profile");
                    wprintf(L"\n");    

                    wprintf(L"\n");
                }
            }
        }

    }
    if (pProfileList != NULL) {
        WlanFreeMemory(pProfileList);
        pProfileList = NULL;
    }

    if (pIfList != NULL) {
        WlanFreeMemory(pIfList);
        pIfList = NULL;
    }

    return dwRetVal;
}

Requisiti

   
Client minimo supportato Windows Vista, Windows XP con SP3 [solo app desktop]
Server minimo supportato Windows Server 2008 [solo app desktop]
Piattaforma di destinazione Windows
Intestazione wlanapi.h (include Wlanapi.h)
Libreria Wlanapi.lib
DLL Wlanapi.dll
Componente ridistribuibile API LAN wireless per Windows XP con SP2

Vedi anche

WLAN_PROFILE_INFO

WLAN_PROFILE_INFO_LIST

WlanDeleteProfile

WlanFreeMemory

WlanGetProfile

WlanGetProfileCustomUserData

WlanOpenHandle

WlanRenameProfile

WlanSaveTemporaryProfile

WlanSetProfile

WlanSetProfileCustomUserData

WlanSetProfileEapUserData

WlanSetProfileEapXmlUserData

WlanSetProfileList

WlanSetProfilePosition