Home All Groups Group Topic Archive Search About
Author
20 Jun 2006 9:55 PM
Xnet
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.

Thanks!

Author
20 Jun 2006 10:17 PM
Mehdi
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();
Author
20 Jun 2006 10:56 PM
Xnet
Work perfect for which it needed...

Thank you very much Mehdi !!!


Show quoteHide quote
"Mehdi" <vio***@REMOVEME.gmail.com> escribió en el mensaje
news:1wipmq2xf96ga$.10wtyqz1j4pin.dlg@40tude.net...
> 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();
Author
1 Aug 2006 8:21 AM
somebody
Hi there

Can you please share the code, I am trying to implement something similar
but it seems to get stuck at the "SetPassword" line

Thanks in advance

Show quoteHide quote
"Xnet" wrote:

> Work perfect for which it needed...
>
> Thank you very much Mehdi !!!
>
>
> "Mehdi" <vio***@REMOVEME.gmail.com> escribió en el mensaje
> news:1wipmq2xf96ga$.10wtyqz1j4pin.dlg@40tude.net...
> > 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();
>
>
>