Herman Cordes
Herman Cordes

Reputation: 4976

Why does removing a local group via WinNT protocol results in a NotImplementedException?

Imagine the following code sample:

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();
        }
    }
}

Why does this code sample work on the LDAP protocol, but throws a NotImplementedException on WinNT? The exception is thrown on the 'CommitChanges' line.

Anyone got a clue? Thanks in advance.

Upvotes: 1

Views: 305

Answers (1)

Herman Cordes
Herman Cordes

Reputation: 4976

Apparently I was doing it wrong... The CommitChanges can safely be omitted, changes are saved on dispose. For future reference, this is the appropriate solution:

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

Upvotes: 2

Related Questions