我有一段使用託管本機WiFi實現的代碼。 它用於獲取連接網絡的配置文件詳情以供在屏幕上顯示。無法獲取Vista/7中連接網絡的配置文件
// 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 /視窗7執行與網絡連接沒有被保存的簡檔,該方法GetProfileXMl引發錯誤
1時18分12秒方法:ThrowIfError
1點18分12秒日誌消息:找不到元素
1點18分12秒堆棧跟蹤:在NativeWifi.Wlan.ThrowIfError(的Int32 win32ErrorCode) 在NativeWifi.WlanClient.WlanI nterface.GetProfileXml(字符串PROFILENAME)
而且據觀察,在Vista和Windows 7,配置文件不是基礎設施連接過程中保存,如果用戶不選擇「自動連接」。此外,adhoc配置文件從不保存,因爲此選項在連接期間未提供給用戶。
有誰知道如何讀取連接的配置文件的XML /細節,即使它沒有保存? 在此先感謝。
感謝您的信息。但恰巧我不再在這家公司工作。因此,我會盡力讓那裏的人學習你給出的解決方案。 :) – Vivek