【发布时间】:2014-01-29 10:28:52
【问题描述】:
我正在尝试以编程方式将计算机添加到我公司的 Active Directory。
我在网上搜索了很久,但我找不到解决方案。
我的代码:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://OU=ou2example,OU=ou1example,DC=site,DC=company,DC=com");
dirEntry.Username = "username";
dirEntry.Password = "password";
DirectoryEntry newComputer = dirEntry.Children.Add("CN=" + ComputerName, "computer");
newComputer.CommitChanges();
我的问题:
计算机已添加到 Active Directory。但它被标记为禁用。
我尝试通过以下方式启用计算机:
newComputer.Properties["userAccountControl"].Value = 0x200;
但我得到一个 DirectoryServicesCOMException --> 服务器无法完成请求。
或
newComputer.Properties["Enabled"].Value = true;
但我得到一个 DirectoryServicesCOMException --> 请求的操作不满足至少一个针对此对象类条件的约束。
请注意,例外情况是从德语翻译成英语的!
感谢您的帮助!
【问题讨论】:
标签: c# active-directory windows-server-2003