2010-09-22 273 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 } 

你還需要檢查它是否已經是組的成員,因爲如果是你會得到一個錯誤。

相關問題