How to change the Active Directory user password?

  • Thread starter Thread starter Jet Leung
  • Start date Start date
J

Jet Leung

Hi all,
How can I modify users in Active Directory ? Actually , I want to change the
Active Directory user password . But how can I do that?
 
You can use something like the following

DirectoryEntry deUser = new
DirectoryEntry("LDAP://CN=TestUser,CN=Users,DC=TestDomain,DC=com");
deUser.Invoke("SetPassword", "NewPassword");
deUser.CommitChanges();

Cheers,
John Wadie
 
Thanks.
But I was comfused about the method name SetPassword. Where is this
method come from? This method no need to delecare?
How many methods I can use by DirectoryEntry? What are their name?
I know DirectoryEntry.Invoke() is a delegate,and as I know a delegate
object must "link" a method which they are in the same type and provide
the same parameter.
But in your code, I can't see any delecare about SetPassword.
 
What makes you think DirectoryEntry.Invoke is a delegate?
It's a regualr method that calls a method (here SetPassword) on the native
COM IADs interface using reflection.
Call it like this:
userEntry.Invoke("SetPassword", object[] {"secret"});

Willy.
 
Thanks
Because if delcare a delegate , it can invoke methods like
a.invoke("method name","parameters"),so when I saw the code like this I
think it is delegate.
In C# DirectoryEntry ,Am I use any ADSI methods and no need to delcare
any object ?
 
You still need to declare objects and sometimes even create a new
instance. You should work through some of the examples in the link I
sent in the last post, I'm sure they can help you out.
 
Thank you !
But I still don't know how to make the IADsUser link the DirectoryEntry
object
this is my code
========
Microsoft.SharePoint.SPWeb
_spweb=Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(this.Con
text);
Microsoft.SharePoint.SPUser _spuser=_spweb.CurrentUser;
m_sCurrentLoginUser=_spuser.LoginName;
ActiveDs.IADsUser _user=(ActiveDs.IADsUser)_spuser;


DirectoryEntry de=new DirectoryEntry(Path);
de.Invoke("_user.ChangePassword",new object[]{m_txtOldPwd.Text
,m_txtNewPwd.Text});
de.CommitChanges();

please tell me the right way and the real sample code
 
Hi Jet:

I'm afraid I don't have any experience with SharePoint at this time,
but I doubt you can cast an SPUser to an IADsUser. You probably want
to extract information about the user to build the path parameter for
the DirectoryEntry.
 
Thanks a lot!
Maybe.. Could you show me the real sample code to change Active
Directory User's password without SharePoint?
I have try that but failed! I don't know how the IADsUser create
relationship with the DirectoryEntry.And how the DirectoryEntry object
can use the method of the IADsUser interface.
Thank you very much!
 
Hi Jet:

IF you send me an email, I can get some code to you on Monday when I'm
finished travelling
 
Hi Scott,
I had sent email on your blog.
Please send me some codes to direct me to finish my work.
Thank you!
 
Back
Top