Last post Jan 25, 2019 05:42 AM by Ackerly Xu
Jan 24, 2019 06:09 AM|pathipati|LINK
I am using below code to reset windows password. but it is throwing below error.
Error: System.UnauthorizedAccessException: Access is denied.
using (var context = new PrincipalContext(ContextType.Machine, domain))
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userName))
Jan 24, 2019 05:16 PM|PatriceSc|LINK
More likely the account under which your application runs is not allowed to change passwords. Rather than granting this access level you could use https://docs.microsoft.com/en-us/dotnet/api/system.directoryservices.accountmanagement.principalcontext.-ctor?view=netframework-4.7.2#System_DirectoryServices_AccountManagement_PrincipalContext__ctor_System_DirectoryServices_AccountManagement_ContextType_System_String_System_String_System_String_ to
use an account allowed to do that...
Jan 25, 2019 05:42 AM|Ackerly Xu|LINK
Maybe you could try user.ChangePassword(oldPassword, newPassword) or use active directory.
You could also try to improve the permission of your application pool by change it to Local System.