Unable to obtain profile of connected network in Vista/7

≯℡__Kan透↙ 提交于 2020-01-06 07:26:10

问题


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");
                }
            }

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 Method : ThrowIfError

01:18:12 Log Message : Element not found

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

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/6578480/unable-to-obtain-profile-of-connected-network-in-vista-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!