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 启用用户帐户
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 使用 rss + c# 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
