2010-12-23 176 views
3

我们有一个员工自助服务应用程序在独立服务器上运行。 该应用程序的功能之一是“忘记密码”,因此员工可以重置自己的密码。 它适用于所有服务器,但不适用于Windows Server 2008 R2。以下是我们使用的代码片段:重置Windows Server 2008 R2上的密码

User.Invoke("SetPassword", new object[] {"#12345Abc"}); 
User.CommitChanges(); 

看起来好像不可能让它在Windows Server 2008 R2中工作。 如果有人有效,请帮助。

谢谢

+0

你得到什么异常? – 2010-12-23 18:45:48

+0

我们得到了异常:“一般访问被拒绝错误”。这很奇怪。我们从本地管理员组提供了一些用户的用户/密码。 – Dionysus 2010-12-23 18:46:44

回答

1

尝试UserPrincipal.SetPassword。这是一个更高层次的抽象,因此更加智能。它会知道调用哪个较低级别的函数。调用方式对我来说似乎太脆弱了。

1

我们也尝试这一个:

PrincipalContext context = new PrincipalContext(ContextType.Machine, "servername"); 

UserPrincipal up = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "username"); 
if (up != null) 
{ 
    up.SetPassword("newpassword"); 
    // We got the same access denied exception here 
    up.Save(); 
} 
相关问题