changing admin password

B

BP

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
 
W

Willy Denoyette [MVP]

BP said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top