2010-09-22 272 views
1

当我尝试将用户从同一个域添加到同一个域的组中时,我有一个完美的功能。将Active Directory子域用户添加到主域组

Function AddUserToGroup(ByVal strUserDN As String, ByVal strGroupDN As String, ByVal strGRPDC As String, ByVal strUserDC As String) As Boolean 
    Dim oUser As DirectoryEntry 
    Dim oGroup As DirectoryEntry 
    Dim blnStatus As Boolean 
    Try 
     oUser = New DirectoryEntry("LDAP://" & strUserDN) 
     oGroup = New DirectoryEntry("LDAP://" & strGroupDN) 
     oGroup.Invoke("Add", oUser.Path.ToString) 
     oGroup.CommitChanges() 
     blnStatus = True 
    Catch ex As Exception 
       //catch error...send email to support 
    End Try 
    oUser = Nothing 
    oGroup = Nothing 
    Return blnStatus 
End Function 

我需要做的是将一个用户从一个子域添加到这个主域组中。例如:

主要领域:geo.com 子域:customer.geo.com

我有一个用户:霍默辛普森谁是customer.geo.com域的成员。我想将此用户添加到geo.com域中的组。我传递正确的完整Active Directory路径,但总是能得到非有用的错误消息:

User: WACUSTDC2/CN=Simpson\, Homer,OU=Geo Test OU,OU=Customers,DC=customer,DC=geo,DC=com 
Group: wadc4/CN=QSGEOTESTOU_RW,OU=Permission Groups,OU=Resources,DC=geo,DC=com 
Error: Exception has been thrown by the target of an invocation. 

错误实际上是被扔在调用线,但正如我刚才所说,如果用户在同一个域中,这完美的作品。

任何想法或建议,非常感谢。

地理...

回答

0

您正在依靠IADsGroup.Add方法。正确的语法是(我想 - 我是一个C#用户):

oGroup.Invoke("Add", new object[] { oUser.Path } 

你还需要检查它是否已经是组的成员,因为如果是你会得到一个错误。

相关问题