C# enable user account with DirectoryEntry(C# 使用 DirectoryEntry 启用用户帐户)
问题描述
我想知道用户帐户是否启用.我使用此代码:
I want to know if user account enable. I use this code:
var usersList = new List<DirectoryEntry>();
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + computerName + ",Computer", Settings.UserName,Settings.UserPassword);
DirectoryEntry admGroup = localMachine.Children.Find(Settings.AdministratorsGroup, "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
var b = member.Properties["userAccountControl"].Value; // <---- value == null
usersList.Add(member);
}
我正确获取了所有成员.
但是member.Properties["userAccountControl"].Value出现错误.我知道使用 System.DirectoryServices.AccountManagement 命名空间,但我想知道为什么此代码不起作用.
I get all members correctly.
But an error is appeared in member.Properties["userAccountControl"].Value. I know of using System.DirectoryServices.AccountManagement namepsace, but i want to know why this code doesn't work.
推荐答案
您正在使用 WinNT:// 提供程序,它的功能非常有限.它不支持成熟的 LDAP:// 提供程序具有的许多常用属性 - 我认为这可能是此代码设置 userAccountControl 的原因(这是一个 LDAP 属性,很可能不存在并且不支持本地用户帐户)不起作用.
You're using the WinNT:// provider, which is very limited in its abilities. It doesn't support many of the usual properties that the full-blown LDAP:// provider has - and I would think that's probably the reason why this code setting userAccountControl (which is an LDAP attribute, most likely not present and not support on a local user account) doesn't work.
请参阅 Richard Mueller 的文章 WinNT 与 LDAP 以了解有关 内容的更多信息WinNT:// 能做(或不能做)
See Richard Mueller's article WinNT vs. LDAP for a lot more information on what WinNT:// can do (or cannot do)
这篇关于C# 使用 DirectoryEntry 启用用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 使用 DirectoryEntry 启用用户帐户
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
