EDN Admin
Well-known member
I am using System.DirectoryServices.AccountManagement to try to add a local account to the local administrators group with the following code but am getting the error below on the group.Members.Add(usr) line. Both usr and group are created as objects
and if I create a Test group, I can add the user to the Test group. I know the group object is the local administrators group and not the domain group because i changed the description on the local administratrors group and the group object is correct
so it appears to be something specific to the local administrators group. Any ideas?
Dim ctx As New PrincipalContext(ContextType.Machine, ".")<br/>
Dim usr As UserPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "TestUserAccount")<br/>
Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(ctx, "Administrators")<br/>
group.Members.Add(usr)<br/>
group.Save()
Error - "System.Runtime.InteropServices.COMException (0x8007200A): The specified directory service attribute or value does not exist.
Thanks
Scott
View the full article
and if I create a Test group, I can add the user to the Test group. I know the group object is the local administrators group and not the domain group because i changed the description on the local administratrors group and the group object is correct
so it appears to be something specific to the local administrators group. Any ideas?
Dim ctx As New PrincipalContext(ContextType.Machine, ".")<br/>
Dim usr As UserPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "TestUserAccount")<br/>
Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(ctx, "Administrators")<br/>
group.Members.Add(usr)<br/>
group.Save()
Error - "System.Runtime.InteropServices.COMException (0x8007200A): The specified directory service attribute or value does not exist.
Thanks
Scott
View the full article