/// <summary> /// Sets the authentication mode on the radius server for the specified network policy. /// </summary> /// <param name="networkPolicy">The network policy name.</param> /// <param name="authenticationModes"><see cref="AuthenticationMode"/></param> /// <param name="priorityMode">The priority <see cref="AuthenticationMode"/> to be set on the server.</param> /// <returns>True if the configuration is successful, else false.</returns> public static bool SetAuthenticationMode(string networkPolicy, AuthenticationMode authenticationModes, AuthenticationMode priorityMode = AuthenticationMode.None) { string configurePolicy = "/C netsh nps set np name = \"{0}\" state = \"enable\" processingorder = \"1\" policysource = \"0\" conditionid = \"0x3d\" conditiondata = \"^15$|^19$|^17$|^18$\" profileid = \"0x100f\" profiledata = \"TRUE\" profileid = \"0x100a\" {1} profileid = \"0x1009\" profiledata = \"0x5\" profiledata = \"0x3\" profiledata = \"0x9\" profiledata = \"0x4\" profiledata = \"0xa\""; string profileData = "profiledata = \"{0}\" "; string authenticationMethod = string.Empty; Logger.LogInfo("Configuring Authentication mode: {0} on radius server.".FormatWith(authenticationModes)); if (priorityMode != AuthenticationMode.None) { Logger.LogInfo("Priority mode: {0}.".FormatWith(priorityMode)); authenticationMethod = profileData.FormatWith(Enum <AuthenticationMode> .Value(priorityMode)); authenticationModes &= ~priorityMode; } foreach (AuthenticationMode item in Enum.GetValues(typeof(AuthenticationMode))) { if (item != AuthenticationMode.None && authenticationModes.HasFlag(item)) { // Construct profile data authenticationMethod += profileData.FormatWith(Enum <AuthenticationMode> .Value(item)); } } string command = configurePolicy.FormatWith(networkPolicy, authenticationMethod); if (ProcessUtil.Execute("cmd.exe", command).StandardOutput.Contains("Ok", StringComparison.CurrentCultureIgnoreCase)) { Logger.LogInfo("Successfully configured the authentication mode: {0} {1} on the radius server.".FormatWith(authenticationModes, priorityMode == AuthenticationMode.None ? string.Empty : "with {0} as priority".FormatWith(priorityMode))); return(true); } else { Logger.LogInfo("Failed to configure the authentication mode: {0} {1} on the radius server.".FormatWith(authenticationModes, priorityMode == AuthenticationMode.None ? string.Empty : "with {0} as priority".FormatWith(priorityMode))); return(true); } }