最近在弄一個工具,使用wlanapi來進行配置無線網路,我發現使用WlanSetProfileEapXmlUserData這個api在win7 64bit上總是報錯1206錯誤,但在win7 32bit上沒有問題。
代碼:https://github.com/wufeng6174/code/tree/master/SetEapData
無線網路的profile: https://github.com/wufeng6174/code/blob/master/sxf-profile.xml
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <Eaptypes.h>
// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")
using namespace std;
int wmain(int argc, char **argv)
{
// Declare and initialize variables.
HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
LPCWSTR xml = L"<?xml version=\"1.0\" ?>\n"
L" <EapHostUserCredentials xmlns=\"http://www.microsoft.com/provisioning/EapHostUserCredentials\"\n"
L" xmlns:eapCommon=\"http://www.microsoft.com/provisioning/EapCommon\" \n"
L" xmlns:baseEap=\"http://www.microsoft.com/provisioning/BaseEapMethodUserCredentials\">\n"
L" <EapMethod>\n"
L" <eapCommon:Type>25</eapCommon:Type> \n"
L" <eapCommon:AuthorId>0</eapCommon:AuthorId> \n"
L" </EapMethod>\n"
L" <Credentials xmlns:eapUser=\"http://www.microsoft.com/provisioning/EapUserPropertiesV1\"\n"
L" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
L" xmlns:baseEap=\"http://www.microsoft.com/provisioning/BaseEapUserPropertiesV1\"\n"
L" xmlns:MsPeap=\"http://www.microsoft.com/provisioning/MsPeapUserPropertiesV1\"\n"
L" xmlns:MsChapV2=\"http://www.microsoft.com/provisioning/MsChapV2UserPropertiesV1\">\n"
L" <baseEap:Eap>\n"
L" <baseEap:Type>25</baseEap:Type> \n"
L" <MsPeap:EapType>\n"
L" <MsPeap:RoutingIdentity>sxf</MsPeap:RoutingIdentity> \n"
L" <baseEap:Eap>\n"
L" <baseEap:Type>26</baseEap:Type> \n"
L" <MsChapV2:EapType>\n"
L" <MsChapV2:Username>52950</MsChapV2:Username> \n"
L" <MsChapV2:Password>dlw6666</MsChapV2:Password> \n"
L" <MsChapV2:LogonDomain></MsChapV2:LogonDomain> \n"
L" </MsChapV2:EapType>\n"
L" </baseEap:Eap>\n"
L" </MsPeap:EapType>\n"
L" </baseEap:Eap>\n"
L" </Credentials>\n"
L" </EapHostUserCredentials>";
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"Num Entries: %lu\n", pIfList->dwNumberOfItems);
wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
dwResult = WlanSetProfileEapXmlUserData(hClient, &pIfList->InterfaceInfo[0].InterfaceGuid, L"sxf", 1, xml, NULL);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanSetProfileEapXmlUserData failed with error: %u\n",
dwResult);
// You can use FormatMessage to find out why the function failed
}
return dwResult;
}
if (pIfList != NULL) {
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
uj5u.com熱心網友回復:
樓主,我和你一樣碰到相同的問題,但是我在 32位上也報錯! Wlansetprofile() 回傳正確,但是WlanSetProfileEapXmlUserData()出錯1206轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/46619.html
標籤:其他技術討論專區
上一篇:JfreeChart常用表格繪制
