在 Windows 问题上连接到企业 WiFi

Connect to Enterprise WiFi on Windows issue

我在 Windows 服务器 2016 上配置了 Radius 服务器,我想使用我的应用程序连接到企业 WiFi 网络。我尝试执行以下步骤:

使用 WlanSetProfile 设置没有凭据的配置文件(我使用从 netsh 导入的配置文件并进行一些修改)

然后使用我的用户名和密码将下面的 xml 配置文件设置为 WlanSetProfileEapXmlUserData:

<?xml version="1.0" ?> 
 <EapHostUserCredentials xmlns="http://www.microsoft.com/provisioning/EapHostUserCredentials" 
   xmlns:eapCommon="http://www.microsoft.com/provisioning/EapCommon" 
   xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapMethodUserCredentials">
   <EapMethod>
     <eapCommon:Type>26</eapCommon:Type> 
     <eapCommon:AuthorId>0</eapCommon:AuthorId> 
   </EapMethod>
   <Credentials xmlns:eapUser="http://www.microsoft.com/provisioning/EapUserPropertiesV1" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapUserPropertiesV1" 
     xmlns:MsPeap="http://www.microsoft.com/provisioning/MsPeapUserPropertiesV1" 
     xmlns:MsChapV2="http://www.microsoft.com/provisioning/MsChapV2UserPropertiesV1">
     <baseEap:Eap>
       <baseEap:Type>26</baseEap:Type> 
       <MsChapV2:EapType>
         <MsChapV2:Username>test</MsChapV2:Username> 
         <MsChapV2:Password>test</MsChapV2:Password> 
       </MsChapV2:EapType>
     </baseEap:Eap>
   </Credentials>
 </EapHostUserCredentials>

然后我使用WlanConnect函数和回调函数来验证连接。连接时出现以下问题:

NotificationCode returns 代码 8 (wlan_notification_acm_scan_fail),然后是 11 (wlan_notification_acm_connection_attempt_fail)。

此外,来自 MS 文档:

wlan_notification_acm_scan_fail:

A scan for connectable networks failed.

The pData member of the WLAN_NOTIFICATION_DATA structure points to a WLAN_REASON_CODE data type value that identifies the reason the WLAN operation failed.

因此,我在出现此问题时检查了 pData,returns 原因如下:

wlan_notification_acm_scan_fail "The operation was successful."

但是网络连接不上。预先感谢您的帮助。

我已经解决了这个问题。问题是因为 PerformServerValidation 设置为 true,它显示通知对话框以验证 Windows 上的证书,这就是它返回的原因:

wlan_notification_acm_scan_fail "The operation was successful."

将 PerformServerValidation 设置为 false 解决了这个问题(WlanSetProfile 函数)。

<PerformServerValidation xmlns=\"http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2\">false</PerformServerValidation>

此外,对于 WlanSetProfileEapXmlUserData 函数,我提供了这个配置文件:

<?xml version="1.0" ?>
<EapHostUserCredentials
xmlns="http://www.microsoft.com/provisioning/EapHostUserCredentials"
xmlns:eapCommon="http://www.microsoft.com/provisioning/EapCommon"
xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapMethodUserCredentials">
<EapMethod>
<eapCommon:Type>25</eapCommon:Type>
<eapCommon:AuthorId>0</eapCommon:AuthorId>
</EapMethod>
<Credentials
xmlns:eapUser="http://www.microsoft.com/provisioning/EapUserPropertiesV1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapUserPropertiesV1"
xmlns:MsPeap="http://www.microsoft.com/provisioning/MsPeapUserPropertiesV1"
xmlns:MsChapV2="http://www.microsoft.com/provisioning/MsChapV2UserPropertiesV1">
<baseEap:Eap>
<baseEap:Type>25</baseEap:Type>
<MsPeap:EapType>
<baseEap:Eap>
<baseEap:Type>26</baseEap:Type>
<MsChapV2:EapType>
<MsChapV2:Username>username</MsChapV2:Username>
<MsChapV2:Password>password</MsChapV2:Password>
</MsChapV2:EapType>
</baseEap:Eap>
</MsPeap:EapType>
</baseEap:Eap>
</Credentials>
</EapHostUserCredentials>

现在已经成功连接到企业网络了。问题已解决。谢谢。

调用 WlanSetProfile() 时,确保将 WlanProfileFlags 设置为 AllUser。