/// <summary> /// Changes the automatic connection and automatic switch elements of a wireless profile. /// </summary> /// <param name="enableAutoConnect">Whether automatic connection should be enabled</param> /// <param name="enableAutoSwitch">Whether automatic switch should be enabled</param> /// <returns>True if successfully changed. False if not.</returns> /// <remarks>A wireless profile made by group policy will be skipped.</remarks> public static bool ChangeProfile(bool enableAutoConnect, bool enableAutoSwitch) { var targetProfile = NativeWifi.EnumerateProfiles() .FirstOrDefault(x => x.ProfileType != ProfileType.GroupPolicy); if (targetProfile == null) { return(false); } if ((targetProfile.Document.IsAutoConnectEnabled == enableAutoConnect) && (targetProfile.Document.IsAutoSwitchEnabled == enableAutoSwitch)) { return(false); } // Set IsAutoConnectEnabled first. targetProfile.Document.IsAutoConnectEnabled = enableAutoConnect; targetProfile.Document.IsAutoSwitchEnabled = enableAutoSwitch; return(NativeWifi.SetProfile( interfaceId: targetProfile.Interface.Id, profileType: targetProfile.ProfileType, profileXml: targetProfile.Document.Xml, profileSecurity: null, // No change overwrite: true)); }
public async Task <bool> SetProfileParameterAsync(ProfileItem profileItem) { if (!(profileItem is NativeWifiProfileItem item)) { throw new ArgumentException(nameof(profileItem)); } return(await Task.Run(() => NativeWifi.SetProfile(item.InterfaceId, item.ProfileType, item.Xml, null, true))); }
public void SetProfileTest() { Assert.IsTrue(_interfaceId != null, "No wireless interface is connected."); var profileXml = CreateProfileXml(_testProfileName, _testSsidString); var result = NativeWifi.SetProfile(_interfaceId, ProfileType.AllUser, profileXml, null, true); Assert.IsTrue(result, "Failed to set the wireless profile for test."); Assert.IsTrue(NativeWifi.EnumerateProfileNames().Contains(_testProfileName), "The wireless profile for test doesn't appear."); }