Skip to content

UsrMgr_AddUserToLocalGroup

Adds a user to a local group.

  • If the user is already a member of the group, the function returns True without making changes.
  • If the local group doesn’t exist, the function fails.

UsrMgr_AddUserToLocalGroup(sDomainName, sUserName, sGroupName) As Boolean

Where the user account is located: a domain name for a domain user, or the local computer name (gsWorkstationName) for a local user. Ignored when sUserName is INTERACTIVE or S-1-5-4.

Name of the user. To add the built-in INTERACTIVE group, specify INTERACTIVE or its SID S-1-5-4.

Name or SID of the local group, for example Administrators or S-1-5-32-544. The name isn’t case sensitive.

'Add a domain user to a local group
If bStatus Then bStatus = UsrMgr_AddUserToLocalGroup("Domain", "Username", "Group")
'Add a local user to the local Administrators group, specified by its SID
If bStatus Then bStatus = UsrMgr_AddUserToLocalGroup(gsWorkstationName, "Username", "S-1-5-32-544")

Scripting Guidelines

UsrMgr_CreateLocalUser UsrMgr_CreateLocalGroup UsrMgr_RemoveUserFromLocalGroup UsrMgr_IsUserMemberOfLocalGroup Constants Package Property Variables