我有一段使用托管本机 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.ThrowIfError(Int32 win32ErrorCode) 在 NativeWifi.WlanClient.WlanInterface.GetProfileXml(String profileName)
并且已经观察到,在 Vista 和 Windows 7 中,如果用户没有选择“自动连接”,则在连接基础架构期间不会保存配置文件。此外,从不保存临时配置文件,因为在连接期间未向用户提供此选项。
有谁知道如何读取已连接配置文件的 XML/详细信息,即使它没有保存?提前致谢。