如何添加一个用户在不同的Active Directory域在C#中? [英] How to add a user in a different Active Directory Domain in C#?

查看:114
本文介绍了如何添加一个用户在不同的Active Directory域在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的目标是能够从一个Active Directory域添加用户到另一个组在一个单独的Active Directory域。

So my goal is to be able to add a user from one Active Directory Domain to another group in a separate Active Directory Domain.

我想做到这一点在C#。我知道有一个System.DirectoryServices命名空间带班与AD进行沟通,但我不能找到跨域添加用户的任何信息。

I'd like to do this in C#. I know there is a System.DirectoryServices namespace with classes to communicate with AD, but I can't find any information on adding users across domains.

在环境中存在具有相同的父林中的两个域控制器。有2个域之间的一个短暂的信任,我们姑且称之为域A和B。

In the environment there are two domain controllers with the same parent forest. There is a transient trust between the 2 domains, let's call them domains A and B.

我能够从站点B将用户添加到域本地或通用组域A的内部与Active Directory工具。

I'm able to add a user from B to a Domain Local or Universal group inside of domain A with the Active Directory tool.

有谁知道我能做到这一点编程方式使用C#?

Does anyone know how I can do this programmatically using C#?

推荐答案

什么工作对我来说,当我写了code这样做一对夫妇几年前:

What worked for me when I wrote code to do this a couple years back:

  1. 找一个DirectoryEntry为您要添加成员的组。
  2. 在调用来调用该组的DirectoryEntry传递参数的添加作为方法的名称和的在数组成员的Active Directory路径

有些样品code把我的头顶部:

Some sample code off the top of my head:

DirectoryEntry group = new DirectoryEntry(@"LDAP://CN=foo,DC=domainA");
string memberADsPath = @"LDAP://CN=bar,DC=domainB";
group.Invoke("Add", new Object[] {memberADsPath});

这篇关于如何添加一个用户在不同的Active Directory域在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆