System.UnauthorizedAccessException {"Access is denied."}
当我尝试将用户移动到 Active Directory 中的不同组织单位时出现错误。
下面是我正在使用的代码。调用MoveTo
. 如果我注释掉呼叫,MoveTo
则用户的电话号码在CommitChanges
被呼叫时成功更新,这表明这可能不是权限错误。
有没有人能够解释为什么我不能将用户移动到新的 OU?
Try
Using Entry As DirectoryEntry = GetDirectoryEntry(DomainLogin) 'Retrieves the directory entry for the user.
Entry.Properties("telephoneNumber").Value = "9999999" 'This successfully changes the user's phone number
Dim strUserPass As String() = nBase.oAppControl.GetADUsernameAndPassword()
'Create DirectoryEntry for the target OU
Dim newLocation As DirectoryEntry = New DirectoryEntry("LDAP://testgrp.local/OU=Accounts,DC=local", strUserPass(0), strUserPass(1))
Entry.MoveTo(newLocation) 'Throws exception
Entry.CommitChanges()
Return True
End Using
Catch ex As Exception
Return False
End Try