C#实现与用户的DirectoryEntry帐户 [英] C# enable user account with DirectoryEntry
问题描述
我想知道,如果用户帐户启用。我用这个code:
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的。值
。我知道用System.DirectoryServices.AccountManagement namepsace的,但我想知道为什么code不起作用。
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://
汇市 - 我会认为这可能是为什么这code设置 userAccountControl的
(这是一个LDAP属性,很可能不是present,不支持本地用户帐户)无法正常工作。
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.
请参阅理查德·穆勒的文章 WINNT与LDAP 了解了很多东西<$ C更多信息$ C> WINNT:// 能做(或不能做)
See Richard Mueller's article WinNT vs. LDAP for a lot more information on what WinNT://
can do (or cannot do)
这篇关于C#实现与用户的DirectoryEntry帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!