/// <summary> /// Gets the information of all profiles on this interface. /// </summary> /// <returns>The profiles information.</returns> public Wlan.WlanProfileInfo[] GetProfiles() { IntPtr profileListPtr; Wlan.ThrowIfError( Wlan.WlanGetProfileList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, out profileListPtr)); try { Wlan.WlanProfileInfoListHeader header = (Wlan.WlanProfileInfoListHeader)Marshal.PtrToStructure(profileListPtr, typeof(Wlan.WlanProfileInfoListHeader)); Wlan.WlanProfileInfo[] profileInfos = new Wlan.WlanProfileInfo[header.numberOfItems]; long profileListIterator = profileListPtr.ToInt64() + Marshal.SizeOf(header); for (int i = 0; i < header.numberOfItems; ++i) { Wlan.WlanProfileInfo profileInfo = (Wlan.WlanProfileInfo)Marshal.PtrToStructure(new IntPtr(profileListIterator), typeof(Wlan.WlanProfileInfo)); profileInfos[i] = profileInfo; profileListIterator += Marshal.SizeOf(profileInfo); } return(profileInfos); } finally { Wlan.WlanFreeMemory(profileListPtr); } }
/// <summary> /// Gets the information of all profiles on this interface. /// </summary> /// <returns>The profiles information.</returns> public Wlan.WlanProfileInfo[] GetProfiles() { IntPtr profileListPtr; Wlan.ThrowIfError( Wlan.WlanGetProfileList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, out profileListPtr)); try { Wlan.WlanProfileInfoListHeader header = (Wlan.WlanProfileInfoListHeader)Marshal.PtrToStructure(profileListPtr, typeof(Wlan.WlanProfileInfoListHeader)); Wlan.WlanProfileInfo[] profileInfos = new Wlan.WlanProfileInfo[header.numberOfItems]; long profileListIterator = profileListPtr.ToInt64() + Marshal.SizeOf(header); for (int i = 0; i < header.numberOfItems; ++i) { Wlan.WlanProfileInfo profileInfo = (Wlan.WlanProfileInfo)Marshal.PtrToStructure(new IntPtr(profileListIterator), typeof(Wlan.WlanProfileInfo)); profileInfos[i] = profileInfo; profileListIterator += Marshal.SizeOf(profileInfo); } return profileInfos; } finally { Wlan.WlanFreeMemory(profileListPtr); } }
public Main() { InitializeComponent(); thisAssembly = Assembly.GetExecutingAssembly(); SystemEvents.SessionSwitch += SessionChangeHandler_SessionChanged; if (File.Exists("settings.xml")) { try { CurrentSettings = SettingsSerializer.Deserialize(File.Open("settings.xml", FileMode.Open)) as Settings.Settings; } catch (Exception ex) { MessageBox.Show(ex.Message, "Settings Read Error"); Close(); Application.Exit(); Environment.Exit(0); } } else { SettingsSerializer.Serialize(File.Open("settings.xml", FileMode.CreateNew), new Settings.Settings()); MessageBox.Show("settings.xml not found, created blank", "Settings Error"); Close(); Application.Exit(); Environment.Exit(0); } NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; bool exists = false; WlanClient client = new WlanClient(); foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) { foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles()) { if (profileInfo.profileName == CurrentSettings.WifiProfile) { exists = true; preferredProfile = profileInfo; wifiInterface = wlanIface; } } } if (!exists) { MessageBox.Show("Preferred Wifi (" + CurrentSettings.WifiProfile + ") not found, please connect to it first and remember settings", "Error"); Close(); Application.Exit(); Environment.Exit(0); } exists = false; NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface n in adapters) { if (n.Name == CurrentSettings.EthernetInterface) { exists = true; } } if (!exists) { MessageBox.Show("Ethernet adapter (" + CurrentSettings.EthernetInterface + ") not found, please check adapter name", "Error"); Close(); Application.Exit(); Environment.Exit(0); } exists = false; foreach (NetworkInterface n in adapters) { if (n.Name == CurrentSettings.WifiInterface) { exists = true; } } if (!exists) { MessageBox.Show("Wifi adapter (" + CurrentSettings.WifiInterface + ") not found, please check adapter name", "Error"); Close(); Application.Exit(); Environment.Exit(0); } NetworkChange_NetworkAddressChanged(null, EventArgs.Empty); }