2011-07-05 43 views
0

我有一段使用托管本机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 /细节,即使它没有保存? 在此先感谢。

回答

1

如果启动连接之前注册的通知(见here),你应该能够收到wlan_notification_acm_connection_complete通知时检查WLAN_CONNECTION_NOTIFICATION_DATA structure的strProfileXml领域。

+0

感谢您的信息。但恰巧我不再在这家公司工作。因此,我会尽力让那里的人学习你给出的解决方案。 :) – Vivek

相关问题