如何确定是否用户帐户是启用还是禁用

编程入门 行业动态 更新时间:2024-10-26 00:27:09
本文介绍了如何确定是否用户帐户是启用还是禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我扔一起快速的C#赢形式的应用程序,以帮助解决一个重复的文职工作。

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?

推荐答案

这code在这里应该工作...

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); }

更多推荐

如何确定是否用户帐户是启用还是禁用

本文发布于:2023-05-27 17:41:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/297755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帐户   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!