获取 WinNT 组的成员列表
关于堆栈溢出有几个与此类似的问题,但不完全相同。
我想在 win xp 计算机上打开或创建一个本地组并向其中添加成员、域、本地和众所周知的帐户。 我还想检查用户是否已经是会员,这样我就不会两次添加相同的帐户,并且可能会出现异常。
到目前为止,我开始将 DirectoryEntry 对象与 WinNT://
提供程序一起使用。 一切顺利,但我不知道如何获取群组成员列表?
有人知道怎么做吗? 或者提供比使用 DirectoryEntry 更好的解决方案?
There are a couple of questions similar to this on stack overflow but not quite the same.
I want to open, or create, a local group on a win xp computer and add members to it, domain, local and well known accounts. I also want to check whether a user is already a member so that I don't add the same account twice, and presumably get an exception.
So far I started using the DirectoryEntry object with the WinNT://
provider. This is going ok but I'm stuck on how to get a list of members of a group?
Anyone know how to do this? Or provide a better solution than using DirectoryEntry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,花了一段时间,尝试了不同的解决方案,但下面给出了最适合我原来问题的解决方案。 我无法使用“标准”方法让 DirectoryEntry 对象访问本地组的成员,我可以让它枚举成员的唯一方法是使用 Invoke 方法调用本机对象 Members 方法。
我还使用类似的技术在本地组中添加和删除成员。
希望这也对其他人有帮助。
基思.
Tim 编辑:添加了 VB.Net 版本
Okay, it's taken a while, messing around with different solutions but the one that fits best with my original question is given below. I can't get the DirectoryEntry object to access the members of a local group using the 'standard' methods, the only way I could get it to enumerate the members was by using the Invoke method to call the native objects Members method.
I also used a similar technique to add and remove members from the local group.
Hopefully this helps someone else as well.
Keith.
EDIT by Tim: added VB.Net version
Microsoft .NET Framework 提供了用于使用 Active Directory 的标准库:System.DirectoryServices 命名空间 在 System.DirectoryServices.dll 中。
Microsoft 建议使用 System.DirectoryServices 命名空间中的两个主要类:DirectoryEntry 和 DirectorySearcher。 在大多数情况下,仅使用 DirectorySearcher 类就足够了。
以下是来自一篇出色的CodeProject 文章的示例:
获取属于特定 AD 组的用户列表
Microsoft .NET Framework provides a standard library for working with Active Directory: System.DirectoryServices namespace in the System.DirectoryServices.dll.
Microsoft recommends using two main classes from the System.DirectoryServices namespace: DirectoryEntry and DirectorySearcher. In most cases, it is enough to use DirectorySearcher class only.
Here is an example from an excellent CodeProject article:
Get a list of users belonging to a particular AD group
您应该能够在
中找到此信息表示组的
属性。DirectoryEntry
上的“member”You should be able to find this information inside the
"member"
attribute on theDirectoryEntry
that represents the group.