GSF.Identity.UserInfo.UserIsInLocalGroup C# (CSharp) Méthode

UserIsInLocalGroup() public static méthode

Determines if user is in 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 detect Active Directory user accounts and groups that may exist in the local group when the userName is prefixed with a domain name and a backslash "\".
or was null. No or was specified. Could not determine if user was in local group.
public static UserIsInLocalGroup ( string groupName, string userName ) : bool
groupName string Group name to test.
userName string User name to test.
Résultat bool
        public static bool UserIsInLocalGroup(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 determine if user is in local group: no group name was specified.", nameof(groupName));

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

            groupName = ValidateGroupName(groupName);

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

            return WindowsUserInfo.UserIsInLocalGroup(groupName, userName);
        }