本文介绍了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 启用用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:32