为什么通过WinNT协议删除本地组会导致NotImplementedException?

时间:2013-02-12 12:55:14

标签: c# .net directoryservices directoryentry

想象一下以下代码示例:

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”行上会抛出异常。

任何人都有线索?提前谢谢。

1 个答案:

答案 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);
        }
    }
}