Connecting Tech Pros Worldwide Help | Site Map

How to change the Active Directory user password?

Jet Leung
Guest
 
Posts: n/a
#1: Nov 16 '05
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?


John Wadie
Guest
 
Posts: n/a
#2: Nov 16 '05

re: How to change the Active Directory user password?


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

Jet Leung
Guest
 
Posts: n/a
#3: Nov 16 '05

re: How to change the Active Directory user password?


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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Nov 16 '05

re: How to change the Active Directory user password?


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.

"Jet Leung" <xivi@tom.com> wrote in message
news:uy4TLjgsEHA.3152@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


Scott Allen
Guest
 
Posts: n/a
#5: Nov 16 '05

re: How to change the Active Directory user password?


It's because programming ADSI from C# can be a right royal pain in the
rear end. Most of the ADSI functionality is still in COM, and it's a
bit of a quirky API to start with - even from late bound VBScript.

There is a list of examples here:

Quick List for C# Code Examples
http://msdn.microsoft.com/library/de...e_examples.asp

This includes how to change passwords, and how to use Invoke and
InvokeMember.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 14 Oct 2004 09:13:49 -0700, Jet Leung <xivi@tom.com> wrote:
[color=blue]
>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.
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it![/color]

Jet Leung
Guest
 
Posts: n/a
#6: Nov 16 '05

re: How to change the Active Directory user password?


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 ?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Scott Allen
Guest
 
Posts: n/a
#7: Nov 16 '05

re: How to change the Active Directory user password?


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.

--
Scott
http://www.OdeToCode.com/

On Thu, 14 Oct 2004 18:33:26 -0700, Jet Leung <xivi@tom.com> wrote:
[color=blue]
>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 ?
>
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it![/color]

Jet Leung
Guest
 
Posts: n/a
#8: Nov 16 '05

re: How to change the Active Directory user password?


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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Scott Allen
Guest
 
Posts: n/a
#9: Nov 16 '05

re: How to change the Active Directory user password?


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.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 15 Oct 2004 00:13:16 -0700, Jet Leung <xivi@tom.com> wrote:
[color=blue]
>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
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it![/color]

Jet Leung
Guest
 
Posts: n/a
#10: Nov 16 '05

re: How to change the Active Directory user password?


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!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Scott Allen
Guest
 
Posts: n/a
#11: Nov 16 '05

re: How to change the Active Directory user password?


Hi Jet:

IF you send me an email, I can get some code to you on Monday when I'm
finished travelling

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 15 Oct 2004 10:13:36 -0700, Jet Leung <xivi@tom.com> wrote:
[color=blue]
>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!
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it![/color]

Jet Leung
Guest
 
Posts: n/a
#12: Nov 16 '05

re: How to change the Active Directory user password?


Hi Scott,
I had sent email on your blog.
Please send me some codes to direct me to finish my work.
Thank you!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread