Change local administrator password in C#

前端 未结 2 480
星月不相逢
星月不相逢 2020-12-09 12:21

I am looking for a way to change the password of a local user account (local Administrator) on a Windows (XP in this case) machine. I have read the CodeProject article about

相关标签:
2条回答
  • 2020-12-09 12:49

    Try the DirectoryEntry class instead of ManagementObject class.

    0 讨论(0)
  • 2020-12-09 13:05

    As Ely noted, you can use the System.DirectoryServices code to accomplish this per MSDN:

    String myADSPath = "LDAP://onecity/CN=Users,
         DC=onecity,DC=corp,DC=fabrikam,DC=com";
    
    // Create an Instance of DirectoryEntry.
    DirectoryEntry myDirectoryEntry = new DirectoryEntry(myADSPath);
    myDirectoryEntry.Username = UserName;
    myDirectoryEntry.Password = SecurelyStoredPassword;
    
    0 讨论(0)
提交回复
热议问题