I'm experiencing some problems when unlocking a locked account on AD.
I'll keep it very simple. I'm assuming that the account is currently locked.
UserPrincipal oUserPrincipal = ADMethods.GetUser("test.user");
oUserPrincipal.UnlockAccount();
oUserPrincipal.Save();`
oUserPrincipal is returned using an Admin account on the TEST AD though a PrincipalContext
Now ..
oUserPrincipal.UnlockAccount(); is generating an exception
System.UnauthorizedAccessException
When checking the logs on the "Test AD server", it's returning a failed negotiation stating that "test.user" is locked out. Since I'm returning a user principal using an admin account, why is unlockAccount method generating an error?
Would appreciate your help.
Exception is as follows.
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)