You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WlanGetProfileList重启设备后无法返回已创建配置文件问题求助

WlanGetProfileList重启后返回空列表的问题排查与解决

我之前在处理WINCE7的WiFi配置问题时也碰到过类似的情况,结合你的代码和问题描述,给你几个实用的排查方向和解决办法:

问题回顾

原生API WlanGetProfileList 在设备重启前能正常返回WiFi配置文件列表,但重启后调用返回空结果——但Windows Compact 7的注册表中仍能看到已创建的配置文件。你使用WLANTOOL启用WiFi功能,核心获取配置列表的代码如下:

BOOL WlanInterfaces::ListProfileList(LPCWSTR strAdapter) { 
    BOOL bResult = FALSE; 
    DWORD dwError = ERROR_SUCCESS; 
    PWLAN_PROFILE_INFO_LIST pProfileList = NULL; 

    do { 
        if(FALSE == Init()) break; 

        WLAN_INTERFACE_INFO* pInterface = NULL; 
        if(!GetInterface(strAdapter,&pInterface)) break; 

        dwError = WlanGetProfileList(*phClientHandle, &pInterface->InterfaceGuid, NULL, &pProfileList); 
        if(ERROR_SUCCESS != dwError) { 
            PrintMsg(L"WlanGetProfileList() Failed Error : %d",dwError); 
            break; 
        } 

        if(NULL == pProfileList) { 
            PrintMsg(L"WlanGetProfileList() returned NULL ProfileList"); 
            break; 
        } 

        for(DWORD i =0;i<pProfileList->dwNumberOfItems;i++) { 
            PrintMsg(L""); 
            PrintMsg(L"Index : %lu",i); 
            PrintMsg(L"Flags : %lu",pProfileList->ProfileInfo[i].dwFlags); 
            PrintMsg(L"ProfileName : %s",pProfileList->ProfileInfo[i].strProfileName); 
            ListProfile(strAdapter,pProfileList->ProfileInfo[i].strProfileName); 
        } 

        bResult = TRUE; 
    }while(FALSE); 

    if(pProfileList) WlanFreeMemory(pProfileList); 
    return bResult; 
} 

可能的原因与解决思路

1. WLAN服务未完全加载就调用API

重启后,WINCE7的WLAN服务可能还没完成初始化,此时调用WlanGetProfileList会获取不到数据。

  • 解决办法:在调用API前增加1-2秒的延迟,或者先检查并确保WLAN服务已启动。可以通过StartService函数启动wlansvc服务,确认服务状态后再执行查询。

2. 接口GUID失效或未刷新

重启后,WiFi接口的GUID可能发生变化,而你的GetInterface函数依赖传入的strAdapter参数,可能获取到的是旧的无效GUID。

  • 解决办法:替换固定适配器名称的逻辑,先调用WlanEnumInterfaces枚举所有当前可用的WiFi接口,再针对每个接口调用WlanGetProfileList,确保使用的是最新的接口GUID。

3. WLAN服务未加载注册表中的配置

虽然注册表中存在配置文件,但WLAN服务可能没有自动加载这些配置。

  • 解决办法:在调用WlanGetProfileList前,先调用WlanRefreshInterface强制刷新接口配置,触发服务重新读取注册表中的配置文件:
// 在调用WlanGetProfileList前添加
dwError = WlanRefreshInterface(*phClientHandle, &pInterface->InterfaceGuid, NULL);
if (dwError != ERROR_SUCCESS) {
    PrintMsg(L"WlanRefreshInterface Failed Error: %d", dwError);
    // 可根据情况重试或退出
}

4. WLAN客户端句柄未重新初始化

重启后,之前初始化的phClientHandle可能已经失效,需要重新调用WlanOpenHandle获取新的有效句柄。

  • 解决办法:检查你的Init()函数,确保重启后会重新执行WlanOpenHandle,生成新的客户端句柄,而不是复用之前的无效句柄。

代码调整示例

这里给你调整后的枚举接口+查询配置的示例片段,替换原来依赖strAdapter的逻辑:

BOOL WlanInterfaces::ListProfileList() { 
    BOOL bResult = FALSE; 
    DWORD dwError = ERROR_SUCCESS; 
    PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
    PWLAN_PROFILE_INFO_LIST pProfileList = NULL; 

    do { 
        if(FALSE == Init()) break; 

        // 枚举所有可用WiFi接口
        dwError = WlanEnumInterfaces(*phClientHandle, NULL, &pIfList);
        if(dwError != ERROR_SUCCESS) {
            PrintMsg(L"WlanEnumInterfaces Failed Error: %d", dwError);
            break;
        }

        // 遍历每个接口查询配置文件
        for(DWORD ifIdx = 0; ifIdx < pIfList->dwNumberOfItems; ifIdx++) {
            WLAN_INTERFACE_INFO* pInterface = &pIfList->InterfaceInfo[ifIdx];
            PrintMsg(L"Processing Interface: %ws", pInterface->strInterfaceDescription);

            // 刷新接口配置
            dwError = WlanRefreshInterface(*phClientHandle, &pInterface->InterfaceGuid, NULL);
            if(dwError != ERROR_SUCCESS) {
                PrintMsg(L"WlanRefreshInterface Failed Error: %d", dwError);
                continue;
            }

            // 获取配置文件列表
            dwError = WlanGetProfileList(*phClientHandle, &pInterface->InterfaceGuid, NULL, &pProfileList); 
            if(ERROR_SUCCESS != dwError) { 
                PrintMsg(L"WlanGetProfileList() Failed Error : %d",dwError); 
                continue; 
            } 

            if(NULL == pProfileList) { 
                PrintMsg(L"WlanGetProfileList() returned NULL ProfileList"); 
                continue; 
            } 

            for(DWORD i =0;i<pProfileList->dwNumberOfItems;i++) { 
                PrintMsg(L""); 
                PrintMsg(L"Index : %lu",i); 
                PrintMsg(L"Flags : %lu",pProfileList->ProfileInfo[i].dwFlags); 
                PrintMsg(L"ProfileName : %s",pProfileList->ProfileInfo[i].strProfileName); 
                ListProfile(pInterface->strInterfaceDescription, pProfileList->ProfileInfo[i].strProfileName); 
            } 

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

        bResult = TRUE; 
    }while(FALSE); 

    if(pProfileList) WlanFreeMemory(pProfileList);
    if(pIfList) WlanFreeMemory(pIfList);
    return bResult; 
} 

内容的提问来源于stack exchange,提问作者samiaj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:17:18