AddOrRemoveRolesFromUser2

Adds or removes a user from one or more roles.

Syntax

<HsvSecurityAccess>.AddOrRemoveRolesFromUser2 bstrUserSID, varalRoles, varabAdd

Argument

Description

bstrUserSID

String (ByVal). The security identifier of the user being assigned to or removed from the roles.

varalRoles

Long array (ByVal). The IDs of the roles.

This array has a one-to-one correspondence with the varabAdd argument’s array. For example, the third element of the varabAdd array indicates whether the user is added to or removed from the role identified by the third element of this array.

Tip:

To get a role’s ID from its name, use GetRoleID.

varabAdd

Boolean array (ByVal). Indicates whether the user should be assigned to or removed from the roles. For each array element, specify TRUE to assign, FALSE to remove.

Example

The following subroutine adds the specified roles to a given user. The subroutine takes an array of role IDs and the user’s security identifier.

Sub assignRolesToUser(laRoles() As Long, sSID As String)
Dim cSecurity As HsvSecurityAccess, bAdd() As Boolean
'g_cSession is an HsvSession object reference
Set cSecurity = g_cSession.Security
ReDim bAdd(UBound(laRoles))
For i = LBound(laRoles) To UBound(laRoles)
  bAdd(i) = True
Next i
cSecurity.AddOrRemoveRolesFromUser2 sSID, laRoles, bAdd
End Sub