【问题标题】:Unable to obtain profile of connected network in Vista/7在 Vista/7 中无法获取已连接网络的配置文件
【发布时间】:2011-09-28 12:57:36
【问题描述】:

我有一段使用托管本机 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/详细信息,即使它没有保存? 提前致谢。

【问题讨论】:

    标签: c# windows-7 windows-vista adhoc wlanapi


    【解决方案1】:

    如果您在启动连接之前注册通知(请参阅here),您应该能够在收到 wlan_notification_acm_connection_complete 通知时检查 WLAN_CONNECTION_NOTIFICATION_DATA structure 的 strProfileXml 字段。

    【讨论】:

    • 感谢您的信息。但碰巧我不再受雇于那家公司。因此,我将尝试让某人在那里研究您提供的解决方案。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多