如何确定用户帐户是启用还是禁用
- 作者: 我要一所大房子
- 来源: 51数据库
- 2022-10-21
问题描述
我正在拼凑一个快速的 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);
}
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
