On Tue, 20 Jun 2006 18:55:46 -0300, Xnet wrote:
I need to change password of a local user of a W2003, without Active
Directory.
I need to do it from an application created with VB2005.
Even if you do not have an active directory server, you can still change a
local user password with Active Directory (seems weird but it works). This
is C# code, sorry, but it should be straightforward enough to translate to
VB. Note that this is a "hardcore" reset of a user password so i'm not sure
of what would happen if the user had used Window's encryption mechanisms to
encrypt some of his personnal files (presumably, they'll be lost) or what
would happen if you try to change the password while the user is already
logged in. If you want to do a "nice" password change (that is, if you know
what the original password is), then there might be better ways of doing
it.
using System.DirectoryServices;
....
// That's the local Active Directory
DirectoryEntry localDirectory = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry user = null;
string username = "John";
string password = "newPassword";
//Look for the user on the local machine
try
{
user = localDirectory.Children.Find(username, "user");
}
catch(Exception ex)
{
// This user doesn't exist or something went wrong
}
// Set the new password for this user
user.Invoke("SetPassword", new Object[] {password});
user.CommitChanges();