无法在Vista/7中获取已连接网络的配置文件 [英] Unable to obtain profile of connected network in Vista/7

查看:155
本文介绍了无法在Vista/7中获取已连接网络的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段使用托管本机WiFi实现的代码. 用于获取所连接网络的配置文件详细信息以在屏幕上显示.

I have a piece of code implemented using the Managed Native WiFi. It is used to obtain the profile details of the connected network for displaying on screen.

 
               // 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都会引发错误

Whenever this code is executed in Vista/Windows 7 and a network is connected without the profiles being saved, the method GetProfileXMl throws an error

01:18:12方法:ThrowIfError

01:18:12 Method : ThrowIfError

01:18:12日志消息:找不到元素

01:18:12 Log Message : Element not found

01:18:12堆栈跟踪:在NativeWifi.Wlan.ThrowIfError(Int32 win32ErrorCode) 在NativeWifi.WlanClient.WlanInterface.GetProfileXml(String profileName)

01:18:12 Stack Trace : at NativeWifi.Wlan.ThrowIfError(Int32 win32ErrorCode) at NativeWifi.WlanClient.WlanInterface.GetProfileXml(String profileName)

并且已经观察到,在Vista和Windows 7中,如果用户未选择自动连接",则在连接基础结构期间不会保存配置文件.另外,由于在连接过程中未向用户提供此选项,因此从不保存即席配置文件.

And it has been observed that in Vista and Windows 7, profiles are not saved during connection for Infrastructure if user doesn't select "Connect Automatically". Also, adhoc profiles are never saved as this option is not provided to user during connection.

有没有人知道如何读取已连接配置文件的XML/详细信息,即使未保存它也是如此? 预先感谢.

Does anyone know how to read the XML/details of a connected profile even when it is not saved? Thanks in advance.

推荐答案

如果在启动连接之前注册通知(请参阅结构.

If you register for notifications before the connection is initiated (see here) you should be able to examine the strProfileXml field of the WLAN_CONNECTION_NOTIFICATION_DATA structure when a wlan_notification_acm_connection_complete notification is received.

这篇关于无法在Vista/7中获取已连接网络的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆