本文介紹了使用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#刪除活動目錄中的用戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!