2010-12-23 174 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(); 
} 
相關問題