Question

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.

Was it helpful?

Solution

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);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top