Zjištění, zda je uživatel členem určité skupiny

Funkce:
V deklarační části formuláře zapište:

Private Function IsMember(GroupName As String, _
   UserName As String) As Boolean

   'Vrací True, je-li uživatel členem skupiny, v ostatních případech False
   'POŽADAVKY: ADSI, referenci na  Active DS Type Library,

   Dim oGroup As IADsGroup
   Dim oSysInfo As New WinNTSystemInfo

   Dim oRoot As IADs
   Dim oDomain As IADsDomain
   Dim sDomain As String

   On Error GoTo ErrHandler

   sDomain = oSysInfo.DomainName
   Set oGroup = GetObject("WinNT://" & sDomain & "/" & GroupName)
   IsMember = oGroup.IsMember("WinNT://" & sDomain & "/" & UserName)

ErrHandler:
   Set oSysInfo = Nothing
   Set oGroup = Nothing
   Set oRoot = Nothing
   Set oDomain = Nothing

End Function

Příklad volání:
IsMember "Administrators", "Bozena"

Zpět

Autor: The Bozena