I am coding some C # in Active Directory and endlessly trying to get this to work to no avail. The following code works, and the following code does not follow:
The code below uses "WinNT: //" + Environment.MachineName + "computer" to make the connection and work fine.
DirectoryEntry localMachine = new DirectoryEntry
("WinNT://" + Environment.MachineName + ",Computer");
DirectoryEntry admGroup = localMachine.Children.Find
("Administrators", "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
output.RenderBeginTag("p");
output.Write(member.Name.ToString());
output.RenderBeginTag("p");
}
base.Render(output);
Now I am trying to change the line:
"WinNT://" + Environment.MachineName + ",Computer"
to
"LDAP://MyDomainControllerName"
but it seems that no matter what value I try instead of the value "MyDomainControllerName", it does not work.
To get the value "MyDomainControllerName", I right-clicked on MyComputer and copied the value of the computer name, as suggested elsewhere, but this did not work.
When I try to use the LDAP: // RootDSE option above, this results in the following error:
Active Directory, LDAP://RootDSE
-, ?