【发布时间】:2010-11-10 08:47:12
【问题描述】:
我在解锁 AD 上的锁定帐户时遇到了一些问题。
我会保持非常简单。我假设该帐户当前已被锁定。
UserPrincipal oUserPrincipal = ADMethods.GetUser("test.user");
oUserPrincipal.UnlockAccount();
oUserPrincipal.Save();`
通过 PrincipalContext 使用 TEST AD 上的管理员帐户返回 oUserPrincipal
现在..
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)
【问题讨论】:
-
这个:“访问被拒绝。”,似乎不言自明。
-
是的,但我正在以管理员权限运行可执行文件,并且我使用的服务帐户是服务器和 AD 上的管理员。我可以使用该帐户手动登录服务器并进行更改,但不能通过此代码。知道为什么这会引发 Access denied 异常吗?
标签: c# active-directory account directoryservices unlock