Access denied (Exception from HRESULT: 0x80070005 (EACCESSDENIED)
Hi, I am working in a project with SP2010. I have to manage users in the Active Directory of Windows Server 2008 R2. When I try to change the password of the user, I have the error shown below in the picture. I tested this function in a console application and it's work nice. Also, I tested it in a web application and it's work. But when I try to do this operation with a sharpoint porject I have this error. PS: I grant the user all the provileges in the active directory. Here is the code of the function: public bool ChangePasswordADUser(string logonName, string newPassword) { try { DirectoryEntry result = ReadADUser(logonName); if (result != null) { object o = result.Invoke("SetPassword", new object[] { newPassword }); result.CommitChanges(); return true; } else { return false; } } catch (System.Reflection.TargetInvocationException ex) { return false; } } And there is the exception: Thank you in advance if you can help me.
May 4th, 2012 7:35pm

Hi grandi_hamza, Ive tested your code in my test environment, but it works fine. In my personal opinion, you should check the privileges again, you should verify that the current identity is the user that you want or you can also use SPSecurity.RunWithElevatedPrivileges to run with Application Pool Identity. You can use following code to inspect the current identity: var identity = WindowsIdentity.GetCurrent(); Thanks,Lambda Zhao TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
May 7th, 2012 3:37am

Please ask your question in the SharePoint 2010 forum and not in this pre-SharePoint 2010 forum.<o:p></o:p> SharePoint 2010 - General Questions and Answers http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/threads SharePoint 2010 - Setup, Upgrade,Administration and Operation http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/threads SharePoint 2010 - Using SharePoint Designer, Infopath, and other customization http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/threads SharePoint 2010 - Using Visual Studio with SharePoint and other programming http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/threads Dirk Van den Berghe
May 7th, 2012 3:38am

By the way, when executing your code as a SharePoint solution, remember that the actual account doing the operation in Active Directory is the application pool account assigned to the web application in the IIS application pool assigned to your SharePoint web application. Are you sure you gave that account permissions in Active Directory for doing the modifications?Dirk Van den Berghe
Free Windows Admin Tool Kit Click here and download it now
May 7th, 2012 3:40am

public bool ChangePasswordADUser(string logonName, string newPassword) { try { DirectoryEntry result = ReadADUser(logonName); if (result != null) { SPSecurity.RunWithElevatedPrivileges(delegate(){ System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent(); object o = result.Invoke("SetPassword", new object[] { newPassword }); result.CommitChanges(); }); return true; } else { return false; } } HG
May 9th, 2012 4:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics