2010-04-08 25 views

回答

3

使用.net 3.5:

PrincipalContext context = new PrincipalContext(ContextType.Domain); 
UserPrincipal user = UserPrincipal.FindByIdentity(context, "user"); 

用戶可以更改自己的密碼:

user.ChangePassword("old", "new"); 

或者,如果你作爲AD管理員身份運行,您可以重置:

user.SetPassword("1234567"); 
+0

我認爲OP想更改遠程機器上非域用戶的密碼。 – 2010-04-08 12:34:12

+0

在這種情況下,我相信'ContextType.Machine'應該可以工作。不太確定,從來沒有處理過本地用戶。謝謝。 – Kobi 2010-04-08 12:37:49

+0

是的,我正在尋找修改本地(即非域)用戶的方法。我會嘗試ContextType.Machine,但我將如何告訴它要使用哪臺機器? – 2010-04-08 13:04:29

2

是的,

這可能是w ork與.net 3.5及更高版本,但它需要服務器服務(即文件共享)被啓用並運行。如果它不是?

我只會喜歡歷久彌新,可愛,知府保障ADSI語法正確的從VB.Net組件(其中BTW就像一個魅力)的心臟...例如:

Dim uName as string = "trgtUser" 
Dim uPass as string = "newPass" 
Dim user = GetObject("WinNT://./" & uName & ",user") 
user.SetPassword(uPass) 

那是在本地機器上設置密碼!

玩得開心;)

+0

並且它不需要System.DirectoryServices。 – MK4L 2011-10-27 12:46:24

+0

很酷。我必須嘗試這個。 – 2011-11-17 19:44:29