【问题标题】:DirectoryServices.DirectoryEntry differences between group invoke("remove") and Property["member"].removeDirectoryServices.DirectoryEntry group invoke("remove") 和 Property["member"].remove 的区别
【发布时间】:2017-09-18 12:23:09
【问题描述】:

使用 DirectoryServices.DirectoryEntry class 我正在尝试使用 C# .NET 从活动目录中的组中删除用户条目

我遇到了两种方法,

第一种方式:

DirectoryEntry directoryEntry = new DirectoryEntry(myGroupPath);
directoryEntry.Properties["member"].Remove(userDistinguishedName);
directoryEntry.CommitChanges();

第二种方式

DirectoryEntry directoryEntry = new DirectoryEntry(myGroupPath);
directoryEntry.Invoke("Remove", userDistinguishedName);

根据msdn Invoke documentation,它表示 Invoke 调用本机 Active Directory 域服务对象上的方法。 它与第一种方式有何不同?

【问题讨论】:

    标签: c# .net active-directory directoryservices directoryentry


    【解决方案1】:

    嗯,我做了我的研究,这就是我所达到的。

    让我们从第二种方式

    开始

    DirectoryEntry.Invoke(methodName, ADsPath)

    正如msdn Invoke documentation 提供的那样,Invoke 调用本机 Active Directory 域服务对象上的方法。在我们的例子中,我们调用组成员接口 IADsGroup

    基本上,IADsGroup:

    1. 管理目录服务中的组成员数据。它使您能够获取成员对象、测试给定对象是否属于组,以及向组添加或删除对象。

    2. 是一个实现 IADs & IDispatch 接口的接口。

      a) IADs:为 ADSI 对象提供基本的维护功能。

      • 是一个定义基本对象特性的接口,即ADSI对象的属性和方法。例如。 “Get”是一种通过名称获取属性值的方法。 “类”是一个获取对象模式类名称的属性。
      • 将对象的属性加载到属性缓存中。例如。调用 Invoke(“Remove”) 时,首先将成员属性加载到缓存中。
      • 访问和修改属性缓存中对象的属性值。
      • 提交对持久目录存储的更改。

      b) IDispatch:允许自动化客户端访问的接口,例如 Visual Basic。它将对象、方法和属性公开给支持自动化的编程工具和其他应用程序。

    3。 它提供了管理和扩展directory schema的方法。

    ADSI 定义的接口可以支持您的提供程序的特定属性和语法。但是,提供者可以选择扩展 ADSI 接口定义并支持其他属性。

    所以,如果您在 AD 上使用众所周知的常用操作,ADSI 界面可以为您省去管理 property cache 和忘记 commit changes 的麻烦,这可能是个问题

    DirectoryEntry.Properties[“member”].Remove

    基本上调用ADSI interface to retrieve the value of the property。 IADsGroup 为您做同样的事情。

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 1970-01-01
      • 2013-04-11
      • 2015-02-05
      • 2023-03-30
      • 1970-01-01
      • 2021-01-02
      • 2010-11-09
      • 1970-01-01
      相关资源
      最近更新 更多