1

我正在使用 C# 创建新的计算机帐户。我的目标是允许 IT 帮助台人员在正确的 OU 中安全地将计算机添加到域中。我打算这样做的方式是让他们使用一种工具,该工具将获取相关信息并在 Active Directory 中创建帐户。到目前为止,这一切都很好。只有一个障碍——我不知道如何授予我的员工将计算机加入域的权利。通常在 Active Directory 中,您可以更改允许将新计算机加入域的组。我正在使用 DirectoryServices.AccountManagement,但我无法弄清楚如何在代码中做同样的事情。

这是我的代码:

PrincipalContext oPrincipalContext = GetPrincipalContext(sOU);

//The password is just a random construction.
//The computer SAM Account Name must end with a dollar sign in order for it
//to be usable.
ComputerPrincipal oComputerPrincipal = new ComputerPrincipal(oPrincipalContext, 
                                                             sComputerName + "$", 
                                                             RandomPassword(), 
                                                             true);

//You actually need to save the record before it is actually created
oComputerPrincipal.Save();

这将创建计算机帐户并将它们放在正确的 OU 中。但是,您仍然需要被授予将计算机添加到域的权限,以便将计算机连接到此帐户。我找不到这样做的代码。

作为旁注,我了解我可以授予我的帮助台人员将计算机加入域的权限。但是,问题是他们可以在不使用此工具的情况下这样做。他们不会意识到,当他们这样做时,他们会将计算机发送到错误的 OU。

更新

这是一张更新的图片,向您展示我试图在代码中完成的工作。如下图所示,当我在代码中创建新的计算机帐户时,我试图更改底部框(通过代码)。看看它如何让您指定谁可以将此特定计算机添加到域中?

新建计算机对话框

4

2 回答 2

0

为此,您至少需要在计算机帐户上授予“重置密码”权限。我认为您不需要其他任何东西,但我不记得了。

您可以使用 ActiveDirectoryAccessRule 类来构建 ACE 并将其添加到 ACL。你会想做这样的事情:

var rule = new ActiveDirectoryAccessRule(<user to delegate to>, ActiveDirectoryRights.ExtendedRight, AccessControlType.Allow, new Guid("00299570-246d-11d0-a768-00aa006e0529")

于 2011-10-27T14:55:54.793 回答
0

这是一个可以找到 ExtendedRightAccessRule 的地方

这是一个简单的示例,它允许域用户“user1”为 OU“ForUser1”中的用户重置密码。您只需要允许您的用户将计算机添加到 OU。@Brian Desmon 为您提供 GUID。

/* Connection to Active Directory 
 */ 
DirectoryEntry workingOU = new DirectoryEntry(); 
workingOU.Options.SecurityMasks = SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Dacl | SecurityMasks.Sacl; 
workingOU.Path = "LDAP://WM2008R2ENT:389/ou=ForUser1,dc=dom,dc=fr"; 

/* Retreive Obect security 
 */ 
ActiveDirectorySecurity adsOUSec = workingOU.ObjectSecurity; 

/* Ellaborate the user to delegate 
 */ 
NTAccount ntaToDelegate = new NTAccount("dom", "user1"); 
SecurityIdentifier sidToDelegate = (SecurityIdentifier)ntaToDelegate.Translate (typeof(SecurityIdentifier)); 

/* Specils Guids 
 */ 
Guid UserForceChangePassword = new Guid("00299570-246d-11d0-a768-00aa006e0529"); 
Guid userSchemaGuid = new Guid("BF967ABA-0DE6-11D0-A285-00AA003049E2"); 
Guid pwdLastSetSchemaGuid = new Guid("bf967a0a-0de6-11d0-a285-00aa003049e2"); 

/* Ellaborate ACEs 
 */ 
ExtendedRightAccessRule erarResetPwd = new ExtendedRightAccessRule(ntaToDelegate, AccessControlType.Allow, UserForceChangePassword, ActiveDirectorySecurityInheritance.Descendents, userSchemaGuid); 
PropertyAccessRule parPwdLastSetW = new PropertyAccessRule(ntaToDelegate, AccessControlType.Allow, PropertyAccess.Write, pwdLastSetSchemaGuid, ActiveDirectorySecurityInheritance.Descendents, userSchemaGuid); 
PropertyAccessRule parPwdLastSetR = new PropertyAccessRule(ntaToDelegate, AccessControlType.Allow, PropertyAccess.Read, pwdLastSetSchemaGuid, ActiveDirectorySecurityInheritance.Descendents, userSchemaGuid); 
adsOUSec.AddAccessRule(erarResetPwd); 
adsOUSec.AddAccessRule(parPwdLastSetW); 
adsOUSec.AddAccessRule(parPwdLastSetR); 

workingOU.CommitChanges(); 

已编辑 (2011-11-04)

在我的理解中,你想做的是一种授权;内部 Active-Directory 委派通过对象权限成为现实。在您的情况下,您希望允许用户创建一个计算机帐户。大多数时候,管理员对整个域都这样做:

在此处输入图像描述在此处输入图像描述

如果您尝试它,您将在域节点 ACL(访问控制列表)中看到一个新的 ACE(访问控制条目)。在示例中,我只是将权限委派给一个 OU。


第二版 (2011-11-04)

他是我所写内容的证明:

在此处输入图像描述

如果您查看安全选项卡

在此处输入图像描述

于 2011-10-27T18:48:53.867 回答