想象一下以下代码示例:
void RemoveGroup(string groupName)
{
string path = string.Format("WinNT://domain/myServer/{0}", groupName);
using (DirectoryEntry entry = new DirectoryEntry(path, @"domain\serviceAccount", @"********"))
{
using (DirectoryEntry parent = rootEntry.Parent)
{
parent.Children.Remove(entry);
// Save changes.
parent.CommitChanges();
}
}
}
为什么此代码示例在LDAP协议上有效,但在WinNT上抛出NotImplementedException? “CommitChanges”行上会抛出异常。
任何人都有线索?提前谢谢。
答案 0 :(得分:1)
显然我做错了......可以安全地省略CommitChanges,在dispose上保存更改。为了将来参考,这是适当的解决方案:
void RemoveGroup(string groupName)
{
string path = string.Format("WinNT://domain/myServer/{0}", groupName);
using (DirectoryEntry entry = new DirectoryEntry(path, @"domain\serviceAccount", @"********"))
{
using (DirectoryEntry parent = rootEntry.Parent)
{
parent.Children.Remove(entry);
}
}
}