| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
=?Utf-8?B?dHc=?=
Guest
Posts: n/a
|
Although there is a lot of useful code in the security faq sheet at
http://support.microsoft.com/default...ent/secfaq.asp alot of it I am currently using, I am in need of a way to delete a user programatically and also to manipulate the groups that users are members of. Is there code somewhere to do this. I didn't see it in the security faqs. Thanks for all help |
|
||
|
||||
|
|
|
| |
|
Graham R Seach
Guest
Posts: n/a
|
'Enumerate all users and groups
Public Sub EnumUsersAndGroups() Dim wrk As DAO.Workspace Dim grp As DAO.Group Dim usr As DAO.User Set wrk = DBEngine(0) 'Enumerate the groups Debug.Print "Groups." For Each grp In wrk.Groups Debug.Print vbTab & grp.Name Next grp 'Enumerate the users Debug.Print "Users." For Each usr In wrk.Users Debug.Print vbTab & usr.Name Next usr Set grp = Nothing Set wrk = Nothing End Sub '------- 'Enumerate the users belonging to a specific group Public Sub EnumGroupUsers(strGroup As String) Dim wrk As DAO.Workspace Dim varUser As Variant Set wrk = DBEngine(0) Debug.Print "Users belonging to the '" & strGroup & "' group..." For Each varUser In wrk.Groups(strGroup).Users Debug.Print vbTab & varUser.Name Next varUser Set wrk = Nothing End Sub '------- 'Enumerate the groups a specific user belongs to Public Sub EnumUserGroups(strUser As String) Dim wrk As DAO.Workspace Dim varGroup As Variant Set wrk = DBEngine(0) Debug.Print "Groups to which user '" & strUser & "' belongs..." For Each varGroup In wrk.Users(strUser).Groups Debug.Print vbTab & varGroup.Name Next varGroup Set wrk = Nothing End Sub '------- 'Create a group Public Sub CreateUserGroup(strGroupName As String, _ strPID As String) Dim wrk As DAO.Workspace Dim grp As DAO.Group Set wrk = DBEngine(0) On Error GoTo CreateUserGroupErr 'Create the new group Set grp = wrk.CreateGroup(strGroupName, strPID) ws.Groups.Append grp CreateUserGroupErr: Set grp = Nothing Set wrk = Nothing End Sub '------- 'Delete a group Public Sub DeleteGroup(strGroup As String) On Error Resume Next DBEngine(0).Groups.Delete strGroup End Sub '------- 'Create a user Public Function CreateUserAccount(strUserName As String, _ strPID As String, strPassword As String) Dim wrk As DAO.Workspace Dim usr As DAO.User Set wrk = DBEngine(0) On Error GoTo CreateUserAccountErr 'Create the new user Set usr = wrk.CreateUser(strUserName, strPID, strPassword) wrk.Users.Append usr CreateUserAccountErr: Set usr = Nothing Set wrk = Nothing End Function '------- 'Delete a user Public Sub DeleteUser(strUser As String) On Error Resume Next DBEngine(0).Users.Delete strUser End Sub '------- 'Add a group to a user Public Sub AddGroup2User(strUser As String, _ strGroup As String) Dim wrk As DAO.Workspace Dim usr As DAO.User Dim grp As DAO.Group Set wrk = DBEngine(0) On Error Resume Next 'Create object references Set usr = wrk.Users(strUser) Set grp = usr.CreateGroup(strGroup) 'Add the group to the user's Groups collection usr.Groups.Append grp usr.Groups.Refresh Set usr = Nothing Set grp = Nothing Set wrk = Nothing End Sub '------- 'Add a user to a group Public Sub AddUser2Group(strUser As String, _ strGroup As String) Dim wrk As DAO.Workspace Dim usr As DAO.User Dim grp As DAO.Group Set wrk = DBEngine(0) On Error Resume Next 'Create object references Set grp = wrk.Groups(strUser) Set usr = grp.CreateUser(strUser) 'Add the group to the user's Groups collection grp.Users.Append usr grp.Users.Refresh Set usr = Nothing Set grp = Nothing Set wrk = Nothing End Sub '------- 'Remove a user from a group Public Sub DeleteUserFromGroup(strUser As String, _ strGroup As String) Dim wrk As DAO.Workspace Set wrk = DBEngine(0) On Error Resume Next wrk.Users(strUser).Groups.Delete strGroup Set wrk = Nothing End Sub '------- 'Determine if a user belongs to a specific group Public Function IsUserInGroup (strUser As String, _ strGroup As String) As Boolean Dim wrk As DAO.Workspace Set wrk = DBEngine(0) On Error Resume Next IsUserInGroup = False 'Check in the Users --> Groups collection IsUserInGroup = _ (wrk.Users(strUser).Groups(strGroup).Name = strGroup) 'You can also do it this way... 'Check in the Groups --> Users collection 'IsUserInGroup = _ (wrk.Groups(strGroup).Users(strUser).Name = strUser) Set wrk = Nothing End Function '------- 'Change a user's password Public Sub ChangePassword(strUser As String, _ strOldPassword As String, strNewPassword As String) Dim wrk As DAO.Workspace Dim usr As DAO.User Set wrk = DBEngine(0) Set usr = wrk.Users(strUser) 'Change the password usr.NewPassword strOldPassword, strNewPassword Set usr = Nothing Set wrk = Nothing End Sub Regards, Graham R Seach Microsoft Access MVP Sydney, Australia --------------------------- "tw" <(E-Mail Removed)> wrote in message news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... > Although there is a lot of useful code in the security faq sheet at > http://support.microsoft.com/default...ent/secfaq.asp > alot of it I am currently using, I am in need of a way to delete a user > programatically and also to manipulate the groups that users are members > of. > Is there code somewhere to do this. I didn't see it in the security faqs. > > Thanks for all help |
|
||
|
||||
|
tw
Guest
Posts: n/a
|
Thanks, I check these out.
"Graham R Seach" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > 'Enumerate all users and groups > Public Sub EnumUsersAndGroups() > Dim wrk As DAO.Workspace > Dim grp As DAO.Group > Dim usr As DAO.User > > Set wrk = DBEngine(0) > > 'Enumerate the groups > Debug.Print "Groups." > For Each grp In wrk.Groups > Debug.Print vbTab & grp.Name > Next grp > > 'Enumerate the users > Debug.Print "Users." > For Each usr In wrk.Users > Debug.Print vbTab & usr.Name > Next usr > > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Enumerate the users belonging to a specific group > Public Sub EnumGroupUsers(strGroup As String) > Dim wrk As DAO.Workspace > Dim varUser As Variant > > Set wrk = DBEngine(0) > > Debug.Print "Users belonging to the '" & strGroup & "' group..." > For Each varUser In wrk.Groups(strGroup).Users > Debug.Print vbTab & varUser.Name > Next varUser > > Set wrk = Nothing > End Sub > > '------- > 'Enumerate the groups a specific user belongs to > Public Sub EnumUserGroups(strUser As String) > Dim wrk As DAO.Workspace > Dim varGroup As Variant > > Set wrk = DBEngine(0) > > Debug.Print "Groups to which user '" & strUser & "' belongs..." > For Each varGroup In wrk.Users(strUser).Groups > Debug.Print vbTab & varGroup.Name > Next varGroup > > Set wrk = Nothing > End Sub > > '------- > 'Create a group > Public Sub CreateUserGroup(strGroupName As String, _ > strPID As String) > Dim wrk As DAO.Workspace > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error GoTo CreateUserGroupErr > > 'Create the new group > Set grp = wrk.CreateGroup(strGroupName, strPID) > ws.Groups.Append grp > > CreateUserGroupErr: > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Delete a group > Public Sub DeleteGroup(strGroup As String) > On Error Resume Next > DBEngine(0).Groups.Delete strGroup > End Sub > > '------- > 'Create a user > Public Function CreateUserAccount(strUserName As String, _ > strPID As String, strPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > On Error GoTo CreateUserAccountErr > > 'Create the new user > Set usr = wrk.CreateUser(strUserName, strPID, strPassword) > wrk.Users.Append usr > > CreateUserAccountErr: > Set usr = Nothing > Set wrk = Nothing > End Function > > '------- > 'Delete a user > Public Sub DeleteUser(strUser As String) > On Error Resume Next > DBEngine(0).Users.Delete strUser > End Sub > > '------- > 'Add a group to a user > Public Sub AddGroup2User(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error Resume Next > > 'Create object references > Set usr = wrk.Users(strUser) > Set grp = usr.CreateGroup(strGroup) > > 'Add the group to the user's Groups collection > usr.Groups.Append grp > usr.Groups.Refresh > > Set usr = Nothing > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Add a user to a group > Public Sub AddUser2Group(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error Resume Next > > 'Create object references > Set grp = wrk.Groups(strUser) > Set usr = grp.CreateUser(strUser) > > 'Add the group to the user's Groups collection > grp.Users.Append usr > grp.Users.Refresh > > Set usr = Nothing > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Remove a user from a group > Public Sub DeleteUserFromGroup(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > > Set wrk = DBEngine(0) > On Error Resume Next > > wrk.Users(strUser).Groups.Delete strGroup > > Set wrk = Nothing > End Sub > > '------- > 'Determine if a user belongs to a specific group > Public Function IsUserInGroup (strUser As String, _ > strGroup As String) As Boolean > Dim wrk As DAO.Workspace > > Set wrk = DBEngine(0) > On Error Resume Next > > IsUserInGroup = False > > 'Check in the Users --> Groups collection > IsUserInGroup = _ > (wrk.Users(strUser).Groups(strGroup).Name = strGroup) > > 'You can also do it this way... > 'Check in the Groups --> Users collection > 'IsUserInGroup = _ > (wrk.Groups(strGroup).Users(strUser).Name = strUser) > > Set wrk = Nothing > End Function > > '------- > 'Change a user's password > Public Sub ChangePassword(strUser As String, _ > strOldPassword As String, strNewPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > Set usr = wrk.Users(strUser) > > 'Change the password > usr.NewPassword strOldPassword, strNewPassword > > Set usr = Nothing > Set wrk = Nothing > End Sub > > Regards, > Graham R Seach > Microsoft Access MVP > Sydney, Australia > --------------------------- > > "tw" <(E-Mail Removed)> wrote in message > news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... >> Although there is a lot of useful code in the security faq sheet at >> http://support.microsoft.com/default...ent/secfaq.asp >> alot of it I am currently using, I am in need of a way to delete a user >> programatically and also to manipulate the groups that users are members >> of. >> Is there code somewhere to do this. I didn't see it in the security >> faqs. >> >> Thanks for all help > > |
|
||
|
||||
|
tw
Guest
Posts: n/a
|
I have added the code below to delete a user, and it seems to be working,
however to see the results, you need to exit the project and return. When you return the user is no longer there. "Graham R Seach" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > 'Enumerate all users and groups > Public Sub EnumUsersAndGroups() > Dim wrk As DAO.Workspace > Dim grp As DAO.Group > Dim usr As DAO.User > > Set wrk = DBEngine(0) > > 'Enumerate the groups > Debug.Print "Groups." > For Each grp In wrk.Groups > Debug.Print vbTab & grp.Name > Next grp > > 'Enumerate the users > Debug.Print "Users." > For Each usr In wrk.Users > Debug.Print vbTab & usr.Name > Next usr > > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Enumerate the users belonging to a specific group > Public Sub EnumGroupUsers(strGroup As String) > Dim wrk As DAO.Workspace > Dim varUser As Variant > > Set wrk = DBEngine(0) > > Debug.Print "Users belonging to the '" & strGroup & "' group..." > For Each varUser In wrk.Groups(strGroup).Users > Debug.Print vbTab & varUser.Name > Next varUser > > Set wrk = Nothing > End Sub > > '------- > 'Enumerate the groups a specific user belongs to > Public Sub EnumUserGroups(strUser As String) > Dim wrk As DAO.Workspace > Dim varGroup As Variant > > Set wrk = DBEngine(0) > > Debug.Print "Groups to which user '" & strUser & "' belongs..." > For Each varGroup In wrk.Users(strUser).Groups > Debug.Print vbTab & varGroup.Name > Next varGroup > > Set wrk = Nothing > End Sub > > '------- > 'Create a group > Public Sub CreateUserGroup(strGroupName As String, _ > strPID As String) > Dim wrk As DAO.Workspace > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error GoTo CreateUserGroupErr > > 'Create the new group > Set grp = wrk.CreateGroup(strGroupName, strPID) > ws.Groups.Append grp > > CreateUserGroupErr: > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Delete a group > Public Sub DeleteGroup(strGroup As String) > On Error Resume Next > DBEngine(0).Groups.Delete strGroup > End Sub > > '------- > 'Create a user > Public Function CreateUserAccount(strUserName As String, _ > strPID As String, strPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > On Error GoTo CreateUserAccountErr > > 'Create the new user > Set usr = wrk.CreateUser(strUserName, strPID, strPassword) > wrk.Users.Append usr > > CreateUserAccountErr: > Set usr = Nothing > Set wrk = Nothing > End Function > > '------- > 'Delete a user > Public Sub DeleteUser(strUser As String) > On Error Resume Next > DBEngine(0).Users.Delete strUser > End Sub > > '------- > 'Add a group to a user > Public Sub AddGroup2User(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error Resume Next > > 'Create object references > Set usr = wrk.Users(strUser) > Set grp = usr.CreateGroup(strGroup) > > 'Add the group to the user's Groups collection > usr.Groups.Append grp > usr.Groups.Refresh > > Set usr = Nothing > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Add a user to a group > Public Sub AddUser2Group(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > Dim grp As DAO.Group > > Set wrk = DBEngine(0) > On Error Resume Next > > 'Create object references > Set grp = wrk.Groups(strUser) > Set usr = grp.CreateUser(strUser) > > 'Add the group to the user's Groups collection > grp.Users.Append usr > grp.Users.Refresh > > Set usr = Nothing > Set grp = Nothing > Set wrk = Nothing > End Sub > > '------- > 'Remove a user from a group > Public Sub DeleteUserFromGroup(strUser As String, _ > strGroup As String) > Dim wrk As DAO.Workspace > > Set wrk = DBEngine(0) > On Error Resume Next > > wrk.Users(strUser).Groups.Delete strGroup > > Set wrk = Nothing > End Sub > > '------- > 'Determine if a user belongs to a specific group > Public Function IsUserInGroup (strUser As String, _ > strGroup As String) As Boolean > Dim wrk As DAO.Workspace > > Set wrk = DBEngine(0) > On Error Resume Next > > IsUserInGroup = False > > 'Check in the Users --> Groups collection > IsUserInGroup = _ > (wrk.Users(strUser).Groups(strGroup).Name = strGroup) > > 'You can also do it this way... > 'Check in the Groups --> Users collection > 'IsUserInGroup = _ > (wrk.Groups(strGroup).Users(strUser).Name = strUser) > > Set wrk = Nothing > End Function > > '------- > 'Change a user's password > Public Sub ChangePassword(strUser As String, _ > strOldPassword As String, strNewPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > Set usr = wrk.Users(strUser) > > 'Change the password > usr.NewPassword strOldPassword, strNewPassword > > Set usr = Nothing > Set wrk = Nothing > End Sub > > Regards, > Graham R Seach > Microsoft Access MVP > Sydney, Australia > --------------------------- > > "tw" <(E-Mail Removed)> wrote in message > news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... >> Although there is a lot of useful code in the security faq sheet at >> http://support.microsoft.com/default...ent/secfaq.asp >> alot of it I am currently using, I am in need of a way to delete a user >> programatically and also to manipulate the groups that users are members >> of. >> Is there code somewhere to do this. I didn't see it in the security >> faqs. >> >> Thanks for all help > > |
|
||
|
||||
|
Graham R Seach
Guest
Posts: n/a
|
Works fine for me. Try adding DBEngine(0).Users.Refresh.
'Delete a user Public Sub DeleteUser(strUser As String) On Error Resume Next DBEngine(0).Users.Delete strUser DBEngine(0).Users.Refresh End Sub Regards, Graham R Seach Microsoft Access MVP Sydney, Australia Microsoft Access 2003 VBA Programmer's Reference http://www.wiley.com/WileyCDA/WileyT...764559036.html "tw" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... >I have added the code below to delete a user, and it seems to be working, >however to see the results, you need to exit the project and return. When >you return the user is no longer there. > > "Graham R Seach" <(E-Mail Removed)> wrote in message > news:(E-Mail Removed)... >> 'Enumerate all users and groups >> Public Sub EnumUsersAndGroups() >> Dim wrk As DAO.Workspace >> Dim grp As DAO.Group >> Dim usr As DAO.User >> >> Set wrk = DBEngine(0) >> >> 'Enumerate the groups >> Debug.Print "Groups." >> For Each grp In wrk.Groups >> Debug.Print vbTab & grp.Name >> Next grp >> >> 'Enumerate the users >> Debug.Print "Users." >> For Each usr In wrk.Users >> Debug.Print vbTab & usr.Name >> Next usr >> >> Set grp = Nothing >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Enumerate the users belonging to a specific group >> Public Sub EnumGroupUsers(strGroup As String) >> Dim wrk As DAO.Workspace >> Dim varUser As Variant >> >> Set wrk = DBEngine(0) >> >> Debug.Print "Users belonging to the '" & strGroup & "' group..." >> For Each varUser In wrk.Groups(strGroup).Users >> Debug.Print vbTab & varUser.Name >> Next varUser >> >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Enumerate the groups a specific user belongs to >> Public Sub EnumUserGroups(strUser As String) >> Dim wrk As DAO.Workspace >> Dim varGroup As Variant >> >> Set wrk = DBEngine(0) >> >> Debug.Print "Groups to which user '" & strUser & "' belongs..." >> For Each varGroup In wrk.Users(strUser).Groups >> Debug.Print vbTab & varGroup.Name >> Next varGroup >> >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Create a group >> Public Sub CreateUserGroup(strGroupName As String, _ >> strPID As String) >> Dim wrk As DAO.Workspace >> Dim grp As DAO.Group >> >> Set wrk = DBEngine(0) >> On Error GoTo CreateUserGroupErr >> >> 'Create the new group >> Set grp = wrk.CreateGroup(strGroupName, strPID) >> ws.Groups.Append grp >> >> CreateUserGroupErr: >> Set grp = Nothing >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Delete a group >> Public Sub DeleteGroup(strGroup As String) >> On Error Resume Next >> DBEngine(0).Groups.Delete strGroup >> End Sub >> >> '------- >> 'Create a user >> Public Function CreateUserAccount(strUserName As String, _ >> strPID As String, strPassword As String) >> Dim wrk As DAO.Workspace >> Dim usr As DAO.User >> >> Set wrk = DBEngine(0) >> On Error GoTo CreateUserAccountErr >> >> 'Create the new user >> Set usr = wrk.CreateUser(strUserName, strPID, strPassword) >> wrk.Users.Append usr >> >> CreateUserAccountErr: >> Set usr = Nothing >> Set wrk = Nothing >> End Function >> >> '------- >> 'Delete a user >> Public Sub DeleteUser(strUser As String) >> On Error Resume Next >> DBEngine(0).Users.Delete strUser >> End Sub >> >> '------- >> 'Add a group to a user >> Public Sub AddGroup2User(strUser As String, _ >> strGroup As String) >> Dim wrk As DAO.Workspace >> Dim usr As DAO.User >> Dim grp As DAO.Group >> >> Set wrk = DBEngine(0) >> On Error Resume Next >> >> 'Create object references >> Set usr = wrk.Users(strUser) >> Set grp = usr.CreateGroup(strGroup) >> >> 'Add the group to the user's Groups collection >> usr.Groups.Append grp >> usr.Groups.Refresh >> >> Set usr = Nothing >> Set grp = Nothing >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Add a user to a group >> Public Sub AddUser2Group(strUser As String, _ >> strGroup As String) >> Dim wrk As DAO.Workspace >> Dim usr As DAO.User >> Dim grp As DAO.Group >> >> Set wrk = DBEngine(0) >> On Error Resume Next >> >> 'Create object references >> Set grp = wrk.Groups(strUser) >> Set usr = grp.CreateUser(strUser) >> >> 'Add the group to the user's Groups collection >> grp.Users.Append usr >> grp.Users.Refresh >> >> Set usr = Nothing >> Set grp = Nothing >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Remove a user from a group >> Public Sub DeleteUserFromGroup(strUser As String, _ >> strGroup As String) >> Dim wrk As DAO.Workspace >> >> Set wrk = DBEngine(0) >> On Error Resume Next >> >> wrk.Users(strUser).Groups.Delete strGroup >> >> Set wrk = Nothing >> End Sub >> >> '------- >> 'Determine if a user belongs to a specific group >> Public Function IsUserInGroup (strUser As String, _ >> strGroup As String) As Boolean >> Dim wrk As DAO.Workspace >> >> Set wrk = DBEngine(0) >> On Error Resume Next >> >> IsUserInGroup = False >> >> 'Check in the Users --> Groups collection >> IsUserInGroup = _ >> (wrk.Users(strUser).Groups(strGroup).Name = strGroup) >> >> 'You can also do it this way... >> 'Check in the Groups --> Users collection >> 'IsUserInGroup = _ >> (wrk.Groups(strGroup).Users(strUser).Name = strUser) >> >> Set wrk = Nothing >> End Function >> >> '------- >> 'Change a user's password >> Public Sub ChangePassword(strUser As String, _ >> strOldPassword As String, strNewPassword As String) >> Dim wrk As DAO.Workspace >> Dim usr As DAO.User >> >> Set wrk = DBEngine(0) >> Set usr = wrk.Users(strUser) >> >> 'Change the password >> usr.NewPassword strOldPassword, strNewPassword >> >> Set usr = Nothing >> Set wrk = Nothing >> End Sub >> >> Regards, >> Graham R Seach >> Microsoft Access MVP >> Sydney, Australia >> --------------------------- >> >> "tw" <(E-Mail Removed)> wrote in message >> news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... >>> Although there is a lot of useful code in the security faq sheet at >>> http://support.microsoft.com/default...ent/secfaq.asp >>> alot of it I am currently using, I am in need of a way to delete a user >>> programatically and also to manipulate the groups that users are members >>> of. >>> Is there code somewhere to do this. I didn't see it in the security >>> faqs. >>> >>> Thanks for all help >> >> > > |
|
||
|
||||
|
tw
Guest
Posts: n/a
|
It's there but not working. I see TC's post until after I posted mine, but
it's working like TC said it does. Is there a way to enable the system menu for the admin users, but not for anyone else?? I know there should be a way for me to have a custom menu but I havn't figured it out yet so I have disable the menu on start up and am using a switchboard. but I'd like to also have a menu and include the security features for the admin user. "Graham R Seach" <gseach@NOSPAM_pacificdb.com.au> wrote in message news:(E-Mail Removed)... > Works fine for me. Try adding DBEngine(0).Users.Refresh. > > 'Delete a user > Public Sub DeleteUser(strUser As String) > On Error Resume Next > DBEngine(0).Users.Delete strUser > DBEngine(0).Users.Refresh > End Sub > > Regards, > Graham R Seach > Microsoft Access MVP > Sydney, Australia > > Microsoft Access 2003 VBA Programmer's Reference > http://www.wiley.com/WileyCDA/WileyT...764559036.html > > > "tw" <(E-Mail Removed)> wrote in message > news:(E-Mail Removed)... >>I have added the code below to delete a user, and it seems to be working, >>however to see the results, you need to exit the project and return. When >>you return the user is no longer there. >> >> "Graham R Seach" <(E-Mail Removed)> wrote in message >> news:(E-Mail Removed)... >>> 'Enumerate all users and groups >>> Public Sub EnumUsersAndGroups() >>> Dim wrk As DAO.Workspace >>> Dim grp As DAO.Group >>> Dim usr As DAO.User >>> >>> Set wrk = DBEngine(0) >>> >>> 'Enumerate the groups >>> Debug.Print "Groups." >>> For Each grp In wrk.Groups >>> Debug.Print vbTab & grp.Name >>> Next grp >>> >>> 'Enumerate the users >>> Debug.Print "Users." >>> For Each usr In wrk.Users >>> Debug.Print vbTab & usr.Name >>> Next usr >>> >>> Set grp = Nothing >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Enumerate the users belonging to a specific group >>> Public Sub EnumGroupUsers(strGroup As String) >>> Dim wrk As DAO.Workspace >>> Dim varUser As Variant >>> >>> Set wrk = DBEngine(0) >>> >>> Debug.Print "Users belonging to the '" & strGroup & "' group..." >>> For Each varUser In wrk.Groups(strGroup).Users >>> Debug.Print vbTab & varUser.Name >>> Next varUser >>> >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Enumerate the groups a specific user belongs to >>> Public Sub EnumUserGroups(strUser As String) >>> Dim wrk As DAO.Workspace >>> Dim varGroup As Variant >>> >>> Set wrk = DBEngine(0) >>> >>> Debug.Print "Groups to which user '" & strUser & "' belongs..." >>> For Each varGroup In wrk.Users(strUser).Groups >>> Debug.Print vbTab & varGroup.Name >>> Next varGroup >>> >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Create a group >>> Public Sub CreateUserGroup(strGroupName As String, _ >>> strPID As String) >>> Dim wrk As DAO.Workspace >>> Dim grp As DAO.Group >>> >>> Set wrk = DBEngine(0) >>> On Error GoTo CreateUserGroupErr >>> >>> 'Create the new group >>> Set grp = wrk.CreateGroup(strGroupName, strPID) >>> ws.Groups.Append grp >>> >>> CreateUserGroupErr: >>> Set grp = Nothing >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Delete a group >>> Public Sub DeleteGroup(strGroup As String) >>> On Error Resume Next >>> DBEngine(0).Groups.Delete strGroup >>> End Sub >>> >>> '------- >>> 'Create a user >>> Public Function CreateUserAccount(strUserName As String, _ >>> strPID As String, strPassword As String) >>> Dim wrk As DAO.Workspace >>> Dim usr As DAO.User >>> >>> Set wrk = DBEngine(0) >>> On Error GoTo CreateUserAccountErr >>> >>> 'Create the new user >>> Set usr = wrk.CreateUser(strUserName, strPID, strPassword) >>> wrk.Users.Append usr >>> >>> CreateUserAccountErr: >>> Set usr = Nothing >>> Set wrk = Nothing >>> End Function >>> >>> '------- >>> 'Delete a user >>> Public Sub DeleteUser(strUser As String) >>> On Error Resume Next >>> DBEngine(0).Users.Delete strUser >>> End Sub >>> >>> '------- >>> 'Add a group to a user >>> Public Sub AddGroup2User(strUser As String, _ >>> strGroup As String) >>> Dim wrk As DAO.Workspace >>> Dim usr As DAO.User >>> Dim grp As DAO.Group >>> >>> Set wrk = DBEngine(0) >>> On Error Resume Next >>> >>> 'Create object references >>> Set usr = wrk.Users(strUser) >>> Set grp = usr.CreateGroup(strGroup) >>> >>> 'Add the group to the user's Groups collection >>> usr.Groups.Append grp >>> usr.Groups.Refresh >>> >>> Set usr = Nothing >>> Set grp = Nothing >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Add a user to a group >>> Public Sub AddUser2Group(strUser As String, _ >>> strGroup As String) >>> Dim wrk As DAO.Workspace >>> Dim usr As DAO.User >>> Dim grp As DAO.Group >>> >>> Set wrk = DBEngine(0) >>> On Error Resume Next >>> >>> 'Create object references >>> Set grp = wrk.Groups(strUser) >>> Set usr = grp.CreateUser(strUser) >>> >>> 'Add the group to the user's Groups collection >>> grp.Users.Append usr >>> grp.Users.Refresh >>> >>> Set usr = Nothing >>> Set grp = Nothing >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Remove a user from a group >>> Public Sub DeleteUserFromGroup(strUser As String, _ >>> strGroup As String) >>> Dim wrk As DAO.Workspace >>> >>> Set wrk = DBEngine(0) >>> On Error Resume Next >>> >>> wrk.Users(strUser).Groups.Delete strGroup >>> >>> Set wrk = Nothing >>> End Sub >>> >>> '------- >>> 'Determine if a user belongs to a specific group >>> Public Function IsUserInGroup (strUser As String, _ >>> strGroup As String) As Boolean >>> Dim wrk As DAO.Workspace >>> >>> Set wrk = DBEngine(0) >>> On Error Resume Next >>> >>> IsUserInGroup = False >>> >>> 'Check in the Users --> Groups collection >>> IsUserInGroup = _ >>> (wrk.Users(strUser).Groups(strGroup).Name = strGroup) >>> >>> 'You can also do it this way... >>> 'Check in the Groups --> Users collection >>> 'IsUserInGroup = _ >>> (wrk.Groups(strGroup).Users(strUser).Name = strUser) >>> >>> Set wrk = Nothing >>> End Function >>> >>> '------- >>> 'Change a user's password >>> Public Sub ChangePassword(strUser As String, _ >>> strOldPassword As String, strNewPassword As String) >>> Dim wrk As DAO.Workspace >>> Dim usr As DAO.User >>> >>> Set wrk = DBEngine(0) >>> Set usr = wrk.Users(strUser) >>> >>> 'Change the password >>> usr.NewPassword strOldPassword, strNewPassword >>> >>> Set usr = Nothing >>> Set wrk = Nothing >>> End Sub >>> >>> Regards, >>> Graham R Seach >>> Microsoft Access MVP >>> Sydney, Australia >>> --------------------------- >>> >>> "tw" <(E-Mail Removed)> wrote in message >>> news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... >>>> Although there is a lot of useful code in the security faq sheet at >>>> http://support.microsoft.com/default...ent/secfaq.asp >>>> alot of it I am currently using, I am in need of a way to delete a user >>>> programatically and also to manipulate the groups that users are >>>> members of. >>>> Is there code somewhere to do this. I didn't see it in the security >>>> faqs. >>>> >>>> Thanks for all help >>> >>> >> >> > > |
|
||
|
||||
|
Graham R Seach
Guest
Posts: n/a
|
That behaviour is probably more to do with refreshing the document
collections. You might try: (a) refreshing the Containers collection: CurrentDb.Containers.Refresh (b) refreshing the Documents collection CurrentDb.Containers("Tables").Documents.Refresh (c) explicitly setting access permissions to each object for the user: Public Sub RemoveUserTablePermissions( _ strUserName As String, strTableName As String) Dim db As DAO.Database Dim doc As DAO.Document Set db = CurrentDb Set doc = db.Containers("Tables").Documents(strTableName) doc.UserName = strSomeUser doc.Permissions = dbSecNoAccess Set doc = Nothing Set db = Nothing End Sub Regards, Graham R Seach Microsoft Access MVP Sydney, Australia Microsoft Access 2003 VBA Programmer's Reference http://www.wiley.com/WileyCDA/WileyT...764559036.html "tw" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)... > It's there but not working. I see TC's post until after I posted mine, > but it's working like TC said it does. Is there a way to enable the > system menu for the admin users, but not for anyone else?? I know there > should be a way for me to have a custom menu but I havn't figured it out > yet so I have disable the menu on start up and am using a switchboard. > but I'd like to also have a menu and include the security features for the > admin user. > > "Graham R Seach" <gseach@NOSPAM_pacificdb.com.au> wrote in message > news:(E-Mail Removed)... >> Works fine for me. Try adding DBEngine(0).Users.Refresh. >> >> 'Delete a user >> Public Sub DeleteUser(strUser As String) >> On Error Resume Next >> DBEngine(0).Users.Delete strUser >> DBEngine(0).Users.Refresh >> End Sub >> >> Regards, >> Graham R Seach >> Microsoft Access MVP >> Sydney, Australia >> >> Microsoft Access 2003 VBA Programmer's Reference >> http://www.wiley.com/WileyCDA/WileyT...764559036.html >> >> >> "tw" <(E-Mail Removed)> wrote in message >> news:(E-Mail Removed)... >>>I have added the code below to delete a user, and it seems to be working, >>>however to see the results, you need to exit the project and return. >>>When you return the user is no longer there. >>> >>> "Graham R Seach" <(E-Mail Removed)> wrote in message >>> news:(E-Mail Removed)... >>>> 'Enumerate all users and groups >>>> Public Sub EnumUsersAndGroups() >>>> Dim wrk As DAO.Workspace >>>> Dim grp As DAO.Group >>>> Dim usr As DAO.User >>>> >>>> Set wrk = DBEngine(0) >>>> >>>> 'Enumerate the groups >>>> Debug.Print "Groups." >>>> For Each grp In wrk.Groups >>>> Debug.Print vbTab & grp.Name >>>> Next grp >>>> >>>> 'Enumerate the users >>>> Debug.Print "Users." >>>> For Each usr In wrk.Users >>>> Debug.Print vbTab & usr.Name >>>> Next usr >>>> >>>> Set grp = Nothing >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Enumerate the users belonging to a specific group >>>> Public Sub EnumGroupUsers(strGroup As String) >>>> Dim wrk As DAO.Workspace >>>> Dim varUser As Variant >>>> >>>> Set wrk = DBEngine(0) >>>> >>>> Debug.Print "Users belonging to the '" & strGroup & "' group..." >>>> For Each varUser In wrk.Groups(strGroup).Users >>>> Debug.Print vbTab & varUser.Name >>>> Next varUser >>>> >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Enumerate the groups a specific user belongs to >>>> Public Sub EnumUserGroups(strUser As String) >>>> Dim wrk As DAO.Workspace >>>> Dim varGroup As Variant >>>> >>>> Set wrk = DBEngine(0) >>>> >>>> Debug.Print "Groups to which user '" & strUser & "' belongs..." >>>> For Each varGroup In wrk.Users(strUser).Groups >>>> Debug.Print vbTab & varGroup.Name >>>> Next varGroup >>>> >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Create a group >>>> Public Sub CreateUserGroup(strGroupName As String, _ >>>> strPID As String) >>>> Dim wrk As DAO.Workspace >>>> Dim grp As DAO.Group >>>> >>>> Set wrk = DBEngine(0) >>>> On Error GoTo CreateUserGroupErr >>>> >>>> 'Create the new group >>>> Set grp = wrk.CreateGroup(strGroupName, strPID) >>>> ws.Groups.Append grp >>>> >>>> CreateUserGroupErr: >>>> Set grp = Nothing >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Delete a group >>>> Public Sub DeleteGroup(strGroup As String) >>>> On Error Resume Next >>>> DBEngine(0).Groups.Delete strGroup >>>> End Sub >>>> >>>> '------- >>>> 'Create a user >>>> Public Function CreateUserAccount(strUserName As String, _ >>>> strPID As String, strPassword As String) >>>> Dim wrk As DAO.Workspace >>>> Dim usr As DAO.User >>>> >>>> Set wrk = DBEngine(0) >>>> On Error GoTo CreateUserAccountErr >>>> >>>> 'Create the new user >>>> Set usr = wrk.CreateUser(strUserName, strPID, strPassword) >>>> wrk.Users.Append usr >>>> >>>> CreateUserAccountErr: >>>> Set usr = Nothing >>>> Set wrk = Nothing >>>> End Function >>>> >>>> '------- >>>> 'Delete a user >>>> Public Sub DeleteUser(strUser As String) >>>> On Error Resume Next >>>> DBEngine(0).Users.Delete strUser >>>> End Sub >>>> >>>> '------- >>>> 'Add a group to a user >>>> Public Sub AddGroup2User(strUser As String, _ >>>> strGroup As String) >>>> Dim wrk As DAO.Workspace >>>> Dim usr As DAO.User >>>> Dim grp As DAO.Group >>>> >>>> Set wrk = DBEngine(0) >>>> On Error Resume Next >>>> >>>> 'Create object references >>>> Set usr = wrk.Users(strUser) >>>> Set grp = usr.CreateGroup(strGroup) >>>> >>>> 'Add the group to the user's Groups collection >>>> usr.Groups.Append grp >>>> usr.Groups.Refresh >>>> >>>> Set usr = Nothing >>>> Set grp = Nothing >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Add a user to a group >>>> Public Sub AddUser2Group(strUser As String, _ >>>> strGroup As String) >>>> Dim wrk As DAO.Workspace >>>> Dim usr As DAO.User >>>> Dim grp As DAO.Group >>>> >>>> Set wrk = DBEngine(0) >>>> On Error Resume Next >>>> >>>> 'Create object references >>>> Set grp = wrk.Groups(strUser) >>>> Set usr = grp.CreateUser(strUser) >>>> >>>> 'Add the group to the user's Groups collection >>>> grp.Users.Append usr >>>> grp.Users.Refresh >>>> >>>> Set usr = Nothing >>>> Set grp = Nothing >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Remove a user from a group >>>> Public Sub DeleteUserFromGroup(strUser As String, _ >>>> strGroup As String) >>>> Dim wrk As DAO.Workspace >>>> >>>> Set wrk = DBEngine(0) >>>> On Error Resume Next >>>> >>>> wrk.Users(strUser).Groups.Delete strGroup >>>> >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> '------- >>>> 'Determine if a user belongs to a specific group >>>> Public Function IsUserInGroup (strUser As String, _ >>>> strGroup As String) As Boolean >>>> Dim wrk As DAO.Workspace >>>> >>>> Set wrk = DBEngine(0) >>>> On Error Resume Next >>>> >>>> IsUserInGroup = False >>>> >>>> 'Check in the Users --> Groups collection >>>> IsUserInGroup = _ >>>> (wrk.Users(strUser).Groups(strGroup).Name = strGroup) >>>> >>>> 'You can also do it this way... >>>> 'Check in the Groups --> Users collection >>>> 'IsUserInGroup = _ >>>> (wrk.Groups(strGroup).Users(strUser).Name = strUser) >>>> >>>> Set wrk = Nothing >>>> End Function >>>> >>>> '------- >>>> 'Change a user's password >>>> Public Sub ChangePassword(strUser As String, _ >>>> strOldPassword As String, strNewPassword As String) >>>> Dim wrk As DAO.Workspace >>>> Dim usr As DAO.User >>>> >>>> Set wrk = DBEngine(0) >>>> Set usr = wrk.Users(strUser) >>>> >>>> 'Change the password >>>> usr.NewPassword strOldPassword, strNewPassword >>>> >>>> Set usr = Nothing >>>> Set wrk = Nothing >>>> End Sub >>>> >>>> Regards, >>>> Graham R Seach >>>> Microsoft Access MVP >>>> Sydney, Australia >>>> --------------------------- >>>> >>>> "tw" <(E-Mail Removed)> wrote in message >>>> news:A824E2F0-2894-4EAF-8247-(E-Mail Removed)... >>>>> Although there is a lot of useful code in the security faq sheet at >>>>> http://support.microsoft.com/default...ent/secfaq.asp >>>>> alot of it I am currently using, I am in need of a way to delete a >>>>> user >>>>> programatically and also to manipulate the groups that users are >>>>> members of. >>>>> Is there code somewhere to do this. I didn't see it in the security >>>>> faqs. >>>>> >>>>> Thanks for all help >>>> >>>> >>> >>> >> >> > > |
|
||
|
||||
|
TC
Guest
Posts: n/a
|
Um, currentdb() refreshes all collections automatically. currentdb.<any
collection>.refresh would be superfluous, IMO. Here's an earlier thread to do with a user's permissions /not/ changing until he logged out & back in again: group: this subject: Group permissions set at startup? date: July 2003 HTH, TC |
|
||
|
||||
|
Graham R Seach
Guest
Posts: n/a
|
TC,
<<...currentdb() refreshes all collections automatically...>> Yes, that's true, but it would certainly be superfluous to refresh 100 collections in order to "simplify" refreshing one. Regards, Graham R Seach Microsoft Access MVP Sydney, Australia Microsoft Access 2003 VBA Programmer's Reference http://www.wiley.com/WileyCDA/WileyT...764559036.html "TC" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > Um, currentdb() refreshes all collections automatically. currentdb.<any > collection>.refresh would be superfluous, IMO. > > Here's an earlier thread to do with a user's permissions /not/ changing > until he logged out & back in again: > > group: this > subject: Group permissions set at startup? > date: July 2003 > > HTH, > TC > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DAO Code to remove ALL the groups that a user belongs to | Tony_VBACoder | Microsoft Access Security | 1 | 1st Jul 2004 10:02 PM |
| User groups in VBA Code | Jim Franklin | Microsoft Access | 3 | 28th May 2004 06:26 AM |
| Adding Code Groups and PermissionSets through code | Thomas Delrue | Microsoft Dot NET Framework | 2 | 30th Oct 2003 12:53 PM |
| users switch groups in code | TC | Microsoft Access Security | 4 | 11th Oct 2003 02:38 PM |
| Groups Policy to assign user to Local Machine Power Users Groups. | KA Kueh | Microsoft Windows 2000 Group Policy | 3 | 19th Sep 2003 07:35 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




