"BP" <vz******@veriz on.net> wrote in message
news:eB******** ******@TK2MSFTN GP09.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 NetUserChangePa ssword 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 NetUserChangePa ssword takes 30-45 seconds, but it looks like
you have a network problem.
You can use DirectoryServic es (ADSI wrappers) namespace classes to manage
user accounts on remote system, note however that ADSI is using
NetUserChangePa ssword under the covers, so you will probably have the same
issue as calling NetUserChangePa ssword.
using System.Director yServices;
....
// 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, "remoteadmi n",
"pwd", AuthenticationT ypes.Secure);
object[] password = new object[] {"oldpwd", "newpwd"};
object ret = userEntry.Invok e("ChangePasswo rd", password );
userEntry.Commi tChanges();
Willy.