有人可以通過這個途徑知道某個特定用戶是否是Windows廣告中的禁用用戶?Active Directory是否需要用戶禁用代碼片段?
回答
如果您使用的是.NET 3.5或可以升級到.NET 3.5,請查看新的System.DirectoryServices.AccountManagement
命名空間,這使得許多操作變得輕而易舉。有關介紹,請參閱Managing Directory Security Principals in the .NET Framework 3.5。
在你的情況,你可以寫你的代碼是這樣的:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN")
UserPrincipal user = UserPrincipal.FindByIdentity("somename");
bool locked = user.IsAccountLockedOut();
這就是全部!在.NET 3.5中,用戶和組的大部分日常操作都得到了大幅改善 - 使用這些新功能!
這就是我一直在尋找的!謝謝 ! – abmv 2010-06-15 06:16:24
您需要查詢userAccountControl
屬性。
值userAccountControl
標誌是:
CONST HEX
-------------------------------
SCRIPT 0x0001
ACCOUNTDISABLE 0x0002
HOMEDIR_REQUIRED 0x0008
LOCKOUT 0x0010
PASSWD_NOTREQD 0x0020
PASSWD_CANT_CHANGE 0x0040
ENCRYPTED_TEXT_PWD_ALLOWED 0x0080
TEMP_DUPLICATE_ACCOUNT 0x0100
NORMAL_ACCOUNT 0x0200
INTERDOMAIN_TRUST_ACCOUNT 0x0800
WORKSTATION_TRUST_ACCOUNT 0x1000
SERVER_TRUST_ACCOUNT 0x2000
DONT_EXPIRE_PASSWORD 0x10000
MNS_LOGON_ACCOUNT 0x20000
SMARTCARD_REQUIRED 0x40000
TRUSTED_FOR_DELEGATION 0x80000
NOT_DELEGATED 0x100000
USE_DES_KEY_ONLY 0x200000
DONT_REQ_PREAUTH 0x400000
PASSWORD_EXPIRED 0x800000
TRUSTED_TO_AUTH_FOR_DELEGATION 0x1000000
您需要與System.DirectoryServices
命名空間,並使用該DirectorySearcher
類,以查詢Active Directory,然後驗證爲userAccountControl
標誌屬性。
一個很好的頁面我想您應該諮詢如下:
How to (almost) everything in Active Directory in C#。
你必須去逐位對userAccountControl
標誌屬性比較如以下時:
using (DirectorySearcher searcher = new DirectorySearcher()) {
searcher.SearchRoot = new DirectoryEntry(rootDSE); // Where rootDSE is a string which contains your LDAP path to your domain.
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = string.Format("(&(objectClass=user)(sAMAccountName={0}))", userName);
SearchResult result = null;
try {
result = searcher.FindOne();
} catch (Exception) {
// You know what to do here... =P
}
if (result == null)
return;
DirectoryEntry user = result.GetDirectoryEntry();
bool isAccountDisabled = ((user.Properties("userAccountControl").Value & ACCOUNTDISABLE) == ACCOUNTDISABLE);
}
無論如何這篇幫助?
@David Neale:它是如何被盜的?我參考了我得到的信息。另外,那裏總是有MSDN。最近我一直在使用Active Directory,並且仍然使用Active Directory。我不明白你在說什麼。 – 2010-06-14 13:27:11
最初是因爲你的答案已經被編輯過,然後直接與我的相似。你現在已經花時間編寫了一個很好的綜合答案,所以我收回它。 :) – 2010-06-14 14:13:47
@David Neale:謝謝你的這種解釋。我這樣做是因爲當輸入整個答案時,OP得到他的答案太長了。然後我用一個簡短但直接的答案進來,然後我編輯它以帶來更全面的細節等等。許多人這樣做,所以如果你明白我的意思,他們會保持「第一答案」的等級。無論如何,你有一個非常好的答案,我會upvote。 =) – 2010-06-14 14:43:11
這裏有一個很好的鏈接,廣告運營Howto: (Almost) Everything In Active Directory via C#
您需要查詢userAccountControl的屬性,這是一個逐位標誌,我相信這是514禁用的帳戶,但該值是累積的,所以你就需要解決它出。 (NORMAL ACCOUNT + ACCOUNT DISABLED = 512 + 2 = 514)
。
以下是所有User Account Control flags的參考。
+1感謝您對我的回答發表評論時給予的解釋。我們都有一個很好的答案。 =) – 2010-06-14 14:44:19
- 1. MS CRM 2011是否需要Active Directory
- 2. 使用VBA連接到Active Directory時,是否需要使用ADO?
- 3. Active Directory檢查用戶是否登錄
- 4. 禁用Active Directory非活動用戶
- 5. 在新門戶中禁用Azure Active Directory
- 6. 檢測用戶是否必須重置密碼在Active Directory中
- 7. 查找Active Directory是否通過電子郵件啓用/禁用
- 8. C#代碼錯誤而改變的Active Directory用戶的密碼
- 9. 通過代碼添加Active Directory帳戶所需的權限
- 10. 使用Powershell更新Active Directory中的Active Directory用戶屬性
- 11. Azure Active Directory圖Api - 用戶
- 12. Umbraco Active Directory創建用戶
- 13. 驗證Active Directory用戶
- 14. 是否可以使用過期密碼來驗證Active Directory用戶?
- 15. 您是否需要在IIS下運行以使用PHP LDAP查詢Active Directory
- 16. 短代碼片段需要說明
- 17. Ruby需要github的代碼片段
- 18. 身份驗證的Active Directory用戶沒有要求的用戶名和密碼
- 19. 檢查Azure Active Directory中是否存在用戶B2C
- 20. 檢查用戶是否存在於Active Directory中
- 21. 檢查用戶名是否存在於Microsoft Azure Active Directory中
- 22. 查找用戶是否爲Active Directory組ASP.NET VB的成員?
- 23. 針對全局管理員禁用Azure Active Directory用戶重置密碼按鈕
- 24. 使用LDAP/Java啓用Active Directory用戶
- 25. Active Directory LDAP - 鎖定用戶帳戶
- 26. 我需要使用導入的csv文件從Active Directory中刪除用戶
- 27. 使用Zend Framework創建Active Directory用戶
- 28. ASP.NET MVC5 - 使用Active Directory用戶的DropDownList
- 29. 使用JNDI啓用Active Directory帳戶
- 30. 使用Rails的Active Directory用戶聯合?
+1在整個SO中查找與Active Directory相關的問題總是很有趣。 =) – 2010-06-14 14:44:54