A
arunava78
Hi,
I'm trying to modify an existing AD User (thru C#). I can change the
Name and Password but I'm unable to change the group. I was trying to
remove the user from all groups and then add the user to the specified
group. When I'm trying to remove the user from a group, an error is
coming "The server is unwilling to process the request. (Exception
from HRESULT: 0x80072035) trying to remove a user from group". I'm
giving a code block here:
//change group membership
//first remove user from other groups
ArrayList arlGroups = GetGroups(LoginID, false);
DirectoryEntry oGroupToRemove = new DirectoryEntry();
for (int i = 0; i < arlGroups.Count; i++)
{
string sGroup = arlGroups.ToString();
sGroup = sGroup.Substring(0, sGroup.IndexOf(","));
string[] split = sGroup.Split(new Char[] { '=' });
sGroup = split[1].ToString();
oGroupToRemove = oDirEntry.Children.Find("CN=" + sGroup, "group");
//THE NEXT LINE IS CAUSING THE EXCEPTION
oGroupToRemove.Properties["member"].Remove("CN=" + LoginID);
oGroupToRemove.CommitChanges();
oGroupToRemove.Close();
}
//add member to the given group
DirectoryEntry oGroup = new DirectoryEntry();
oGroup = oDirEntry.Children.Find("CN=" + GroupName, "group");
if (oGroup != null)
{
oGroup.Invoke("Add", new object[] { oUser.Path.ToString() });
}
oGroup.CommitChanges();
oGroup.Close();
Please help me as soon as possible.
Thnx in advance
I'm trying to modify an existing AD User (thru C#). I can change the
Name and Password but I'm unable to change the group. I was trying to
remove the user from all groups and then add the user to the specified
group. When I'm trying to remove the user from a group, an error is
coming "The server is unwilling to process the request. (Exception
from HRESULT: 0x80072035) trying to remove a user from group". I'm
giving a code block here:
//change group membership
//first remove user from other groups
ArrayList arlGroups = GetGroups(LoginID, false);
DirectoryEntry oGroupToRemove = new DirectoryEntry();
for (int i = 0; i < arlGroups.Count; i++)
{
string sGroup = arlGroups.ToString();
sGroup = sGroup.Substring(0, sGroup.IndexOf(","));
string[] split = sGroup.Split(new Char[] { '=' });
sGroup = split[1].ToString();
oGroupToRemove = oDirEntry.Children.Find("CN=" + sGroup, "group");
//THE NEXT LINE IS CAUSING THE EXCEPTION
oGroupToRemove.Properties["member"].Remove("CN=" + LoginID);
oGroupToRemove.CommitChanges();
oGroupToRemove.Close();
}
//add member to the given group
DirectoryEntry oGroup = new DirectoryEntry();
oGroup = oDirEntry.Children.Find("CN=" + GroupName, "group");
if (oGroup != null)
{
oGroup.Invoke("Add", new object[] { oUser.Path.ToString() });
}
oGroup.CommitChanges();
oGroup.Close();
Please help me as soon as possible.
Thnx in advance