GSF.Identity.UserInfo.AddUserToLocalGroup C# (CSharp) Method

AddUserToLocalGroup() public static method

Adds an existing user to the specified local groupName.
This function will handle Windows service virtual accounts by specifying the complete virtual account name, such as @"NT SERVICE\MyService", as the userName. This function can also add Active Directory user accounts and groups to the local group the when the userName is prefixed with a domain name and a backslash "\".
or was null. No or was specified. Could not add user to local group.
public static AddUserToLocalGroup ( string groupName, string userName ) : bool
groupName string Group name to add local user to.
userName string Existing local user name.
return bool
        public static bool AddUserToLocalGroup(string groupName, string userName)
        {
            if ((object)groupName == null)
                throw new ArgumentNullException(nameof(groupName));

            if ((object)userName == null)
                throw new ArgumentNullException(nameof(userName));

            // Remove any irrelevant white space
            groupName = groupName.Trim();
            userName = userName.Trim();

            if (groupName.Length == 0)
                throw new ArgumentException("Cannot add user to local group: no group name was specified.", nameof(groupName));

            if (userName.Length == 0)
                throw new ArgumentException("Cannot add user to local group: no user name was specified.", nameof(userName));

            groupName = ValidateGroupName(groupName);

            if (Common.IsPosixEnvironment)
                return UnixUserInfo.AddUserToLocalGroup(groupName, userName);

            return WindowsUserInfo.AddUserToLocalGroup(groupName, userName);
        }