DirectoryServices使用特殊符号'/'时获取错误0x80005000

时间:2013-07-04 02:23:41

标签: directoryservices

当我尝试将ADUser添加到ADGroup时,出现错误(0x80005000)

addUserToGroup(“userA”,“CB HQ(P& D)”); < - 用于在组中添加用户的工作

addUserToGroup(“userb”,“CB HQ(P / D)”); 当程序访问--if(!dirEntry.Properties [“member”]。包含(userPath)) - 将抛出错误(0x80005000)


static void addUserToGroup(String loginName, String groupName){
string groupPath = String.Format("{0}CN={1},OU={2},{3}", LDAPStr, groupName, OUStr, DCStr);
        string userPath = getUserPathByLogin(loginName);
        try
        {
            if (!String.IsNullOrEmpty(userPath))
            {
                DirectoryEntry dirEntry = new DirectoryEntry(groupPath, ADUserName, ADPassword);
                if (!dirEntry.Properties["member"].Contains(userPath))
                {
                    dirEntry.Properties["member"].Add(userPath);
                    dirEntry.CommitChanges();
                }
            }
        }
        catch (Exception ex)
        {


        }

1 个答案:

答案 0 :(得分:0)

固定 在我的情况下,必须用以下编码替换组名。

groupName = groupName.Replace(“/”,“\ /”);