Hello.

I need to programmatically reset a user's password. We will create an
account that has the proper authority to do so.

I've been looking through the .Net framework for a class that might handle
this but am having no luck.

Does anyone have any suggestions?

Thanks in advance,

Mike

Re: Programattically Change Password by Mehdi

Mehdi
Wed Nov 30 10:29:25 CST 2005

Hi,

On Wed, 30 Nov 2005 10:09:23 -0500, MikeL wrote:

> I need to programmatically reset a user's password. We will create an
> account that has the proper authority to do so.
>
> I've been looking through the .Net framework for a class that might handle
> this but am having no luck.
>
> Does anyone have any suggestions?

You can do that through Active Directory (you don't need to actually have
an Active Directory server for this to work, it works fine with the local
Windows accounts).

You'll need to add a reference to the System.DirectoryServices assembly to
your project.


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 wrong happened
}

// Set new password for this user
user.Invoke("SetPassword", new Object[] {password});
user.CommitChanges();

Re: Programattically Change Password by MikeL

MikeL
Thu Dec 01 07:20:04 CST 2005

Hi, Mehdi. Thanks for the response.

That works as long as the account that I'm trying to change is the same
account as the user issuing the command. When I ran my program, which tried
to change the password on a different account, I got an error stating
something to the effect of resources being allocated to a different account,
and that I needed to disconnect and reconnect. I think it's because I was
signed on as me, and I was trying to change another user's account.

My app is sort of a service, so it is not running under the account whose
password needs to be changed.

Any thoughts of what I need to do?

Thanks again,

Mike

"Mehdi" <vioccc@REMOVEME.gmail.com> wrote in message
news:19h4ivrczi594.135k3ab2s2osr$.dlg@40tude.net...
> Hi,
>
> On Wed, 30 Nov 2005 10:09:23 -0500, MikeL wrote:
>
>> I need to programmatically reset a user's password. We will create an
>> account that has the proper authority to do so.
>>
>> I've been looking through the .Net framework for a class that might
>> handle
>> this but am having no luck.
>>
>> Does anyone have any suggestions?
>
> You can do that through Active Directory (you don't need to actually have
> an Active Directory server for this to work, it works fine with the local
> Windows accounts).
>
> You'll need to add a reference to the System.DirectoryServices assembly to
> your project.
>
>
> 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 wrong happened
> }
>
> // Set new password for this user
> user.Invoke("SetPassword", new Object[] {password});
> user.CommitChanges();