无法在Vista/7中获取已连接网络的配置文件
本文关键字:连接 网络 配置文件 获取 Vista | 更新日期: 2023-09-27 18:01:01
我有一段使用Managed Native WiFi实现的代码。它用于获取连接网络的配置文件详细信息,以便在屏幕上显示。
// Start the wireless configuration service if it is stopped
startservice();
WlanClient client = new WlanClient();
bHasWiFi = false;
string strConnectionStatus = Constants.BlankString;
// Enumerate all interfaces
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
bHasWiFi = true;
strConnectionStatus = wlanIface.InterfaceState.ToString();
// Check whether disconnected
if (strConnectionStatus == Constants.Disconnected)
{
IsConnected = false;
continue; //iterate to next interface if any
}
else
{
string strProfileName = wlanIface.CurrentConnection.profileName.ToString();
ErrorLog.WriteLogMsg("Connected Profile : " + strProfileName);
strDefaultNetwork = wlanIface.CurrentConnection.wlanAssociationAttributes.dot11BssType.ToString();
ErrorLog.WriteLogMsg("Connected Network Type : " + strDefaultNetwork);
if (strProfileName.Length != 0)
{
// Obtain Profile XML
string strXmlProfile = wlanIface.GetProfileXml(strProfileName);
// Read channel information if OS not Windows XP
if(strCurOS != Constants.WindowsXP)
intChannel = wlanIface.Channel;
// Extract profile information
GetNetworkProfileXML(ref IsConnected, ref strDefaultAuth, ref strDefaultSSID, ref strDefaultEnc, ref strDefaultKey, wlanIface, ref strXmlProfile);
// Process and store the profile data
GetDatfromProfiles(strDefaultNetwork, strDefaultAuth, strDefaultSSID, strDefaultEnc, strDefaultKey, strCurOS, intChannel);
}
else
{
ErrorLog.WriteLogMsg("Blank profile name");
IsConnected = false; // Set error flag
}
break;
}
}
// Error cases
if (!IsConnected || !bHasWiFi)
{
if (!bHasWiFi)
throw new Exception("Unable to enumerate the wireless interfaces");
else if (!IsConnected)
throw new Exception("WiFi is not configured or is disconnected");
}
}
每当在Vista/Windows 7中执行此代码,并且在没有保存配置文件的情况下连接网络时,GetProfileXMl方法会抛出错误
01:18:12方法:ThrowIfError
01:18:12日志消息:元素未找到
01:18:12堆栈跟踪:在NativeWifi.Wlan.SthrowIfError(Int32 win32ErrorCode(在NativeWifi.WlanClient.WlanInterface.GetProfileXml(字符串配置文件名称(
据观察,在Vista和Windows7中,如果用户不选择"自动连接",则在连接基础结构时不会保存配置文件。此外,由于在连接过程中不向用户提供此选项,因此永远不会保存临时配置文件。
有人知道如何读取连接的配置文件的XML/详细信息吗?提前谢谢。
如果在启动连接之前注册通知(请参阅此处(,则在收到WLAN_NOTIFICATION_amc_connection_complete通知时,您应该能够检查WLAN_connection_NOTIFICATION_DATA结构的strProfileXml字段。