/// <summary> /// Gets a specified wireless profile information. /// </summary> /// <param name="clientHandle">Client handle</param> /// <param name="interfaceInfo">Interface information</param> /// <param name="profileName">Profile name</param> /// <param name="signalQuality">Signal quality</param> /// <param name="position">Position in preference order</param> /// <param name="isConnected">Whether this profile is connected to a wireless LAN</param> /// <returns>Wireless profile information</returns> /// <remarks> /// For profile elements, see /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms707381.aspx /// </remarks> private static ProfilePack GetProfile(SafeClientHandle clientHandle, InterfaceInfo interfaceInfo, string profileName, int signalQuality, int position, bool isConnected) { ProfileType profileType; var source = Base.GetProfile(clientHandle, interfaceInfo.Id, profileName, out profileType); if (string.IsNullOrWhiteSpace(source)) { return(null); } XElement rootXml; using (var sr = new StringReader(source)) rootXml = XElement.Load(sr); var ns = rootXml.Name.Namespace; var ssidXml = rootXml.Descendants(ns + "SSID").FirstOrDefault(); var ssidHexadecimalString = ssidXml?.Descendants(ns + "hex").FirstOrDefault()?.Value; var ssidBytes = ConvertFromHexadecimalStringToBytes(ssidHexadecimalString); var ssidString = ssidXml?.Descendants(ns + "name").FirstOrDefault()?.Value; var connectionTypeXml = rootXml.Descendants(ns + "connectionType").FirstOrDefault(); var bssType = ConvertToBssType(connectionTypeXml?.Value); var connectionModeXml = rootXml.Descendants(ns + "connectionMode").FirstOrDefault(); var isAutomatic = (connectionModeXml?.Value.Equals("auto", StringComparison.OrdinalIgnoreCase)).GetValueOrDefault(); var authenticationXml = rootXml.Descendants(ns + "authentication").FirstOrDefault(); var authentication = authenticationXml?.Value; var encryptionXml = rootXml.Descendants(ns + "encryption").FirstOrDefault(); var encryption = encryptionXml?.Value; //Debug.WriteLine("SSID: {0}, BssType: {1}, Authentication: {2}, Encryption: {3}, Automatic: {4}", // ssidString, // bssType, // authentication, // encryption, // isAutomatic); return(new ProfilePack( name: profileName, interfaceInfo: interfaceInfo, profileType: profileType, profileXml: source, ssid: new NetworkIdentifier(ssidBytes, ssidString), bssType: bssType, authentication: authentication, encryption: encryption, signalQuality: signalQuality, position: position, isAutomatic: isAutomatic, isConnected: isConnected)); }