问题描述
我正在拼凑一个快速的 C# win 表单应用程序来帮助解决重复的文书工作.
I am throwing together a quick C# win forms app to help resolve a repetitive clerical job.
我在 AD 中搜索了所有用户帐户,并将它们添加到带有复选框的列表视图中.
I have performed a search in AD for all user accounts and am adding them to a list view with check boxes.
我想默认 listviewitems 的默认检查状态取决于帐户的启用/禁用状态.
I would like to default the listviewitems' default check state to depend upon the enabled/disabled state of the account.
string path = "LDAP://dc=example,dc=local";
DirectoryEntry directoryRoot = new DirectoryEntry(path);
DirectorySearcher searcher = new DirectorySearcher(directoryRoot,
"(&(objectClass=User)(objectCategory=Person))");
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult result in results)
{
DirectoryEntry de = result.GetDirectoryEntry();
ListViewItem lvi = new ListViewItem(
(string)de.Properties["SAMAccountName"][0]);
// lvi.Checked = (bool) de.Properties["AccountEnabled"]
lvwUsers.Items.Add(lvi);
}
我正在努力寻找正确的属性来解析以从 DirectoryEntry 对象中获取帐户的状态.我搜索了 AD 用户属性,但没有找到任何有用的信息.
I'm struggling to find the right attribute to parse to get the state of the account from the DirectoryEntry object. I've searched for AD User attributes, but not found anything useful.
任何人都可以提供任何指示吗?
Can anyone offer any pointers?
推荐答案
这里的代码应该可以工作...
this code here should work...
private bool IsActive(DirectoryEntry de)
{
if (de.NativeGuid == null) return false;
int flags = (int)de.Properties["userAccountControl"].Value;
return !Convert.ToBoolean(flags & 0x0002);
}
这篇关于如何确定用户帐户是启用还是禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)