有人可以通过这个途径知道某个特定用户是否是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