"BP" <vz******@verizon.net> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Can anyone point me to some C# code/info that would allow me to change the
Administrator password on a remote machine in a workgroup? Not a domain,
no Active Directory present. I realize I need to know the current
password. I've written code to extractall kinds of WMI info from these
machines remotely, so am familiar with the need to connect and
authenticate. I've even been successful importing the Netapi32.dll and
using the NetUserChangePassword call, however this seems to take 30 to 45
seconds per machine to complete. I've seen VBScript to do the same, but
would like to control this within my C# pgm. Thanks
Not sure why NetUserChangePassword takes 30-45 seconds, but it looks like
you have a network problem.
You can use DirectoryServices (ADSI wrappers) namespace classes to manage
user accounts on remote system, note however that ADSI is using
NetUserChangePassword under the covers, so you will probably have the same
issue as calling NetUserChangePassword.
using System.DirectoryServices;
....
// bind to remote system using WinNT provider using user credentials with
sufficient privileges to execute a changepassword!
string userPath = "WinNT://machineName/administrator";
DirectoryEntry userEntry = new DirectoryEntry(userPath, "remoteadmin",
"pwd", AuthenticationTypes.Secure);
object[] password = new object[] {"oldpwd", "newpwd"};
object ret = userEntry.Invoke("ChangePassword", password );
userEntry.CommitChanges();
Willy.