Delete user in active directory using c#(使用c#删除活动目录中的用户)
问题描述
我已经写了一些代码但不起作用,它抛出异常发生操作错误."代码--->
I've written some code but not works it throws Exception "An operations error occurred." code --->
DirectoryEntry dirEntry = new DirectoryEntry("LDAP path", "admin-username", "admin-password");
dirEntry.Properties["member"].Remove("username-delete");
dirEntry.CommitChanges();
dirEntry.Close();
给我一些摆脱这些事情的想法..
give me some ideas to get out of this things..
推荐答案
如果您使用 .NET 3.5 及更高版本,您应该查看 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间.在此处阅读所有相关信息:
If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:
- 在 .NET Framework 3.5 中管理目录安全主体
- System.DirectoryServices.AccountManagement 上的 MSDN 文档
基本上,您可以定义域上下文并轻松找到 AD 中的用户和/或组:
Basically, you can define a domain context and easily find users and/or groups in 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 中与用户和组一起玩变得非常容易!
The new S.DS.AM makes it really easy to play around with users and groups in AD!
这篇关于使用c#删除活动目录中的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用c#删除活动目录中的用户
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
