DirectoryEntry domian = null;
IsConnected("dachkj.com", "liubq", "abcd1234!", out domian);
if (domian != null)
{
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = domian;
deSearch.Filter = "(&(objectClass=organizationalUnit)(OU=技术部))";
SearchResultCollection results = deSearch.FindAll();
if (results.Count > 0)
{
DirectoryEntry parentOuEntry = results[0].GetDirectoryEntry();
DirectoryEntries dentrys = parentOuEntry.Children;
DirectoryEntry organizeEntry = dentrys.Find("OU=技术小组", "organizationalUnit");
dentrys.Remove(organizeEntry);
organizeEntry.CommitChanges();
//ouEntry.UsePropertyCache = true;
//ouEntry.Rename("OU=技术小组1");
//DirectoryEntry OU = ouEntry.Children.Add("OU=技术小组", "organizationalUnit");
//OU.CommitChanges();
//ouEntry.CommitChanges();
}
}
在执行Remove抛异常,里面所用到的对象都能正常获取,很奇怪,求大神指点迷津!