WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Error 241 when Trying to Remove a User from Group

Keywords: 	 error 241 remove user

Question:

I tried to remove a user from the group "Domain Users" but it gives error 241 "object not a member of group". I believe this is because it is by default set as the Primary group.

If that user is a member of 2 groups and a different group is set to the primary group then it can be removed from the group fine. So... Is there any way I can set the primary group? Or any other way to accomplish this?

I am aware that this "primary group" can be set on WIndows NT using "wntUserSetDat" But...Since my user is in a OrgUnit I dont think I can use the wnt functions because they wont deal with users except if they are in the "user" folder (I assume microsoft uses this for backward compatibility)

AddExtender("wwads34I.dll") ; Active Directory Services
AddExtender("WWWNT34I.DLL") ; Window NT/2000 network ; ver 11017 as of 7/20/00
nl='%@crlf%'

Old_style_domain_name='msuding'
DC_domain_name='DC=msuding,DC=yardi,DC=com'

debug(@on)
user_to_remove_from_group='LDAP://%old_style_Domain_Name%/CN=ff1,ou=FF,%DC_domain_name%'
;Group_to_remove_a_user_from='LDAP://%old_style_Domain_Name%/CN=ff,ou=FF,%DC_domain_name%'
Group_to_remove_a_user_from='LDAP://%old_style_Domain_Name%/CN=Domain
Users,cn=Users,%DC_domain_name%'
Message('user and group', '%user_to_remove_from_group% %nl% %Group_to_remove_a_user_from%')
result=dsRemFromGrp(group_to_remove_a_user_from, user_to_remove_from_group)

exit 

Answer:

It's not pretty but it works. This task should be a little more straight forward with the next version of the ADSI extender.
AddExtender("wwads34I.dll")
AddExtender("WWWNT34I.DLL") 

UserObject = "LDAP://Mydomain/cn=Rem
User,ou=testouone,dc=Mydomain,dc=tree,dc=windowware,dc=com"
UserContaner = "LDAP://Mydomain/cn=users,dc=Mydomain,dc=tree,dc=windowware,dc=com"
DomainUserGroup = "LDAP://Mydomain/cn=domain
users,cn=users,dc=Mydomain,dc=tree,dc=windowware,dc=com"
GuestUserGroup = "LDAP://Mydomain/cn=domain
guests,cn=users,dc=Mydomain,dc=tree,dc=windowware,dc=com"
ouContainer = "LDAP://Mydomain/ou=testouone,dc=Mydomain,dc=tree,dc=windowware,dc=com"

; Add user to new group
dsAddToGrp(GuestUserGroup, UserObject)

; Move user to "users" container
tempUserObject = dsMoveObj( UserObject, UserContaner, "" )

; Change primary group.
rid = wntGroupInfo("myserver","domain guests", @GLOBALGROUP, 2)
wntUserSetDat("myserver", "ruser", "primary_group_id" , rid )


; Remove user from old primary group.
dsRemFromGrp(DomainUserGroup, tempUserObject)

; Move user back to old container.
dsMoveObj( tempUserObject, ouContainer, "" )

Article ID:   W14512
Filename:   Error 241 when trying to remove a user from group.txt
File Created: 2001:03:02:14:40:12
Last Updated: 2001:03:02:14:40:12