Listing Users in Groups

Sometimes you will need to know what users belong to what groups. The procedure in Hands-On 17-8 demonstrates how to obtain such a list.

©Hands-On 17-8: Listing Users in Groups

1. Insert a new module and, in the module's Code window, enter the List_UsersInGroups procedure as shown below.

Sub List_UsersInGroups()

Dim conn As ADODB.Connection Dim cat As ADOX.Catalog Dim grp As New ADOX.Group Dim myUser As New ADOX.User Dim strDB As String Dim strSysDb As String strDB = "C:\BookProject\SpecialDb.mdb" strSysDb = "C:\BookProject\Security.mdw"

' Open connection to the database using ' the specified system database Set conn = New ADODB.Connection With conn

.Provider = "Microsoft.Jet.OLEDB.4.0" .Properties("Jet OLEDB:System Database") = strSysDb .Properties("User ID") = "Developer" .Properties("Password") = "chapter17" .Open strDB End With

' Open the catalog Set cat = New ADOX.Catalog cat.ActiveConnection = conn For Each grp In cat.Groups

Debug.Print "Group Name: " & grp.Name If cat.Groups(grp.Name).Users.Count = 0 Then

Debug.Print vbTab & "There are no users in the " & _ grp & " group."

End If

For Each myUser In cat.Groups(grp.Name).Users

Debug.Print vbTab & "User Name: " & myUser.Name

Part II

Next myUser Next grp

Set cat = Nothing conn.Close

Set conn = Nothing

MsgBox "Groups and Users are listed in the Immediate window." End Sub

Figure 17-16: After running the List_UsersInGroup procedure in Hands-On 17-8, security group account names and the corresponding user accounts are listed in the Immediate window.

0 0

Post a comment