本文介绍了如何在VB.NET中克隆UserPrincipal对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从VB.NET应用程序在Active Directory中创建一个新用户.大多数字段将与已经存在的模板"相同.用户,名称,姓氏,电子邮件,SamAccountName等除外.

I'm trying to create a new User in Active Directory from a VB.NET application. Most fields will be identical to an already existing "template" user, except things like Name, SurName, Email, SamAccountName, etc.

因此,我要复制或克隆此模板用户,为几个字段分配新的/不同的值,然后将该新用户保存在Active Directory中.我想避免必须手动将谁知道模板中的多少个属性分配给新用户,并且一路上可能会忘记一些东西.

So I want to copy or clone this template User, assign the few fields with a new/different value and then save this new user in Active Directory. I'd like to avoid having to manually assign who-knows how many properties from my template to the new User and maybe forget something along the way..

有没有办法做到这一点?我发现了一些有关使用DirectoryEntry.CopyTo()的信息,但我只是得到了未实现"的字样.错误,无论如何我都怀疑这是正确的方向(不确定如何与UserPrincipal对象一起使用此类)

Is there not a way to do that? I found something about using DirectoryEntry.CopyTo(), but I simply get a "Not implemented" error, and anyway I doubt this is the right direction (Unsure how to use this class together with a UserPrincipal object)

我应该使用与System.DirectoryServices.AccountManagement.UserPrincipal不同的类将新用户保存在AD中吗?我的方法有误吗?

Should I be using a different class than System.DirectoryServices.AccountManagement.UserPrincipal to save my new user in the AD? Do I have the wrong approach?

任何帮助将不胜感激:)

Any help will be appreciated :)

推荐答案

如果您查看 DirectoryEntry.CopyTo 的源代码,它调用:

If you look at the source code for DirectoryEntry.CopyTo, it calls:

newParent.ContainerObject.CopyHere(Path, newName)

ContainerObject IADsContainer类型.如果您查看有关IADsContainer.CopyHere ,它说(在备注下):

And ContainerObject is of the type IADsContainer. If you look at the documentation for IADsContainer.CopyHere, it says (under Remarks):

ADSI是"Active Directory服务接口".因此,简短的答案是它不适用于AD对象.

ADSI is "Active Directory Service Interfaces". So the short answer is that it just won't work with AD objects.

没有办法做你想做的事.您将必须手动分配要复制的每个属性.

There is no way to do what you want. You will have to manually assign each attribute you want to copy.

这篇关于如何在VB.NET中克隆UserPrincipal对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:09