我正在尝试在当前域中查找用户。代码是这样的:
DirectoryEntry domain = new DirectoryEntry("LDAP://CN-Users, DC=" + Environment.UserDomainName);
DirectoryEntries entries = domain.Children;
try
{
// The following line causes the exception
DirectoryEntry user = entries.Find("(&(objectCategory=user)(cn=" + userName + "))", ActiveDirectoryEntryType.User.TypeName);
user.DeleteTree();
user.CommitChanges();
}
catch
{}
我收到一个错误:
An invalid dn syntax has been specified.
我也尝试了以下代码并得到了同样的错误:
DirectoryEntry user = entries.Find(userName, ActiveDirectoryEntryType.User.TypeName);
我在帮助文件中找不到有关正确语法的信息。有谁知道这是怎么做到的?