0

我在解锁 AD 上的锁定帐户时遇到了一些问题。

我会保持非常简单。我假设该帐户当前已被锁定。

UserPrincipal oUserPrincipal = ADMethods.GetUser("test.user");  
oUserPrincipal.UnlockAccount();  
oUserPrincipal.Save();`

oUserPrincipal 通过 PrincipalContext 使用 TEST AD 上的管理员帐户返回

现在 ..

oUserPrincipal.UnlockAccount(); 正在生成异常

System.UnauthorizedAccessException

检查“测试 AD 服务器”上的日志时,它返回一个失败的协商,说明“test.user”被锁定。由于我使用管理员帐户返回用户主体,为什么 unlockAccount 方法会产生错误?

感谢您的帮助。

例外情况如下。

System.UnauthorizedAccessException: Access is denied.

   at System.DirectoryServices.Interop.UnsafeNativeMetho  ds.IAds.SetInfo()
   at System.DirectoryServices.DirectoryEntry.CommitChan  ges()
   at System.DirectoryServices.AccountManagement.SDSUtil  s.WriteAttribute(String dePath, String attribute, Int32 value, NetCred credentials, AuthenticationTypes authTypes)
   at System.DirectoryServices.AccountManagement.ADStore  Ctx.WriteAttribute(Principal p, String attribute, Int32 value)
   at System.DirectoryServices.AccountManagement.ADStore  Ctx.UnlockAccount(AuthenticablePrincipal p)
   at System.DirectoryServices.AccountManagement.Account  Info.UnlockAccount()
   at ADMethodsAccountManagement.UnlockUserAccount(Strin  g sUserName) in C:\Users\christian.debono\documents\visual studio 2010\Projects\UnlockApp\UnlockApp\ADMethodsAccount  Management.cs:line 182
   at UnlockApp.Form1.UnlockButton_Click(Object sender, EventArgs e) in C:\Users\christian.debono\documents\visual studio 2010\Projects\UnlockApp\UnlockApp\Form1.cs:line 30
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventAr  gs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.O  nMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.W  ndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
4

1 回答 1

0

您确定您使用的服务用户有权解锁帐户吗?我之前遇到过这样一种情况,我们有一个服务用户,他有管理员权限,但在解锁帐户时被拒绝,如果你解锁的帐户比解锁它的帐户具有更高的权限,我猜最好的方法测试它是否您自己的 AD 帐户具有解锁帐户的特权,首先通过解锁所述帐户在 Active Directory 用户和计算机中尝试,然后在成功时在您的代码上再次尝试。希望这是有道理的。

于 2010-11-18T03:59:06.530 回答