Beispiel #1
0
        public void DeleteMember(string domainAndName)
        {
            var groupMember = new WinAPI.NETAPI32.LOCALGROUP_MEMBERS_INFO_3 {
                lgrmi3_domainandname = domainAndName
            };

            var result = WinAPI.NETAPI32.NetLocalGroupDelMembers(
                this.NTCompatibleHostName,
                this.Name,
                3,
                ref groupMember,
                1
                );

            if (result != 0)
            {
                throw new NetApiException(
                          result,
                          "Unable to delete member '{0}' from group '{1}' on host '{2}'",
                          groupMember.lgrmi3_domainandname,
                          Name,
                          Host
                          );
            }
        }
Beispiel #2
0
        /// <summary>
        /// Makes the user a member of the specified local group.
        /// </summary>
        /// <param name="groupName">The local name of the group.</param>
        /// <remarks>The group must be local to the machine this user is defined on (i.e. User.Host)</remarks>
        public void AddMembership(string groupName)
        {
            var newGroupMember = new WinAPI.NETAPI32.LOCALGROUP_MEMBERS_INFO_3 {
                lgrmi3_domainandname = this.Name
            };
            var result = WinAPI.NETAPI32.NetLocalGroupAddMembers(
                this.Host,
                groupName,
                3,
                ref newGroupMember,
                1
                );

            if (result != 0)
            {
                throw new NetApiException(
                          result,
                          "Unable to add group membership '{0}' to user '{1}' on host '{2}'",
                          groupName,
                          Name,
                          Host
                          );
            }
        }