Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a windows server 2012 R2 which not in AD Server.
I have a user "TestUser" on server which can not change its own password.
So, I need login as administrator to reset "TestUser" password.
I tried the codes below, but got access denied error.
How can I change "TestUser" password?

What I have tried:

DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1},user", computerName, "Administrator"), "Administrator", "AdminPW", AuthenticationTypes.Secure);

foreach (DirectoryEntry childEntry in directoryEntry.Parent.Children)
                {
                    if (childEntry.SchemaClassName == "User" && childEntry.Name == "TestUser")
                    {
                        childEntry.Invoke("SetPassword", new object[] { newPassword });
                        childEntry.CommitChanges();
                    }
                }
Posted
Updated 21-Aug-18 20:26pm
v2
Comments
Richard MacCutchan 22-Aug-18 3:50am    
If you are the administrator you can do it by logging into the server and using the standard tools.
Member 10521346 22-Aug-18 23:14pm    
Yeah, but I'm trying to deal this work by code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900