我已经编写了一些代码,但不起作用,它抛出异常“发生操作错误。”
代码--->
DirectoryEntry dirEntry = new DirectoryEntry("LDAP path", "admin-username", "admin-password");
dirEntry.Properties["member"].Remove("username-delete");
dirEntry.CommitChanges();
dirEntry.Close();
给我一些想法来摆脱这些事情..
如果您使用的是 .NET 3.5 及更高版本,您应该查看System.DirectoryServices.AccountManagement
(S.DS.AM) 命名空间。在这里阅读所有相关内容:
- 管理 .NET Framework 3.5 中的目录安全主体
- 关于 System.DirectoryServices.AccountManagement 的 MSDN 文档
基本上,您可以定义域上下文并轻松在 AD 中查找用户和/或组:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find the user you want to delete
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
user.Delete();
}
新的 S.DS.AM 使 AD 中的用户和组的使用变得非常容易!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)