试图从C#更改密码时,访问被拒绝 [英] Access Denied when trying to change password from c#

查看:461
本文介绍了试图从C#更改密码时,访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个工具,允许用户更改其AD-密码。此工具不会对我公司域名的问题,但与Citrix在客户机上运行时,我收到以下错误信息:

I wrote a tool that allows users to change their AD-password. This tool works without problems on my companies domain, but when running it on our customers machine with citrix I receive the following error message:

System.Reflection.TargetInvocationException:异常被抛出调用的目标。 ---> System.UnauthorizedAccessException的:访问被拒绝。 (从HRESULT异常:0X80070005(E_ACCESSDENIED))     ---内部异常堆栈跟踪的结尾---     在System.DirectoryServices.DirectoryEntry.Invoke(字符串方法名,对象[]参数)     在System.DirectoryServices.AccountManagement.SDSUtils.ChangePassword(的DirectoryEntry德,串旧密码,新密码字符串)     在System.DirectoryServices.AccountManagement.ADStoreCtx.ChangePassword(AuthenticablePrincipal磷,字符串旧密码,新密码字符串)     在CitrixPWChangeBackend.ActiveDirectory.ChangePasswordForCurrentUser(字符串oldPw,字符串newPw,布尔和放大器; errorWrongPw,布尔和放大器; errorPasswordRules,字符串和放大器;的errorMessage)

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) --- End of inner exception stack trace --- at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) at System.DirectoryServices.AccountManagement.SDSUtils.ChangePassword(DirectoryEntry de, String oldPassword, String newPassword) at System.DirectoryServices.AccountManagement.ADStoreCtx.ChangePassword(AuthenticablePrincipal p, String oldPassword, String newPassword) at CitrixPWChangeBackend.ActiveDirectory.ChangePasswordForCurrentUser(String oldPw, String newPw, Boolean& errorWrongPw, Boolean& errorPasswordRules, String& errorMessage)

导致该错误的行是:

UserPrincipal.Current.ChangePassword(oldPw, newPw);

当然,

oldPW是正确的,

"oldPW" is correct, of course

推荐答案

神奇的原因是为使财产UserCannotChangePassword是真的,用户的策略。 没有思杰具体问题。

The "magic" reason was a policy for that user causing the property "UserCannotChangePassword" to be true. No Citrix specific issue.

这篇关于试图从C#更改密码时,访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆