views:

41

answers:

1

This code failed on this line with unknown error (0x80005000)

using System; 
using System.DirectoryServices; 

// correct the userPath!!! 
string userPath = "WinNT://"+Environment.MachineName+"/"+Environment.UserDomainName+"//"+Environment.UserName; 

using (DirectoryEntry userEntry = new DirectoryEntry(userPath)) 
{ 
    object[] password = new object[] {"newPwd", "oldPwd"}; 
    object ret = userEntry.Invoke("ChangePassword", password); 
    userEntry.CommitChanges(); 
} 
A: 

You should try to avoid using the WinNT: provider for ADSI - it's old, it's only there for backward compatibility, and it's severely limited in its capabilities.

Is this a user account in a network environment? If so, use the LDAP:// provider instead - it's much more powerful and more flexible in many ways.

Where exactly is your code failling? It's not clear from your post. On the .Invoke() or on the .CommitChanges() call?

marc_s
I change to LDAP:// I still get error on the .Invoke() thanks
Show me the code you're using for the LDAP version! What is the "userpath" look like??
marc_s
"LDAP://"+ Environment.MachineName+"/"+Environment.UserName; - the user is Domain user...
That is *not* going to work! The LDAP path is **not** the same as the WinNT path ! Are you on a Windows network here? Or just a local machine??
marc_s
sorry,I am on a Windows network
Then your LDAP path should be something like: `LDAP://DCserver/cn=Your User,cn=Users,dc=YourCompany,dc=com`. Check out Sysinternals' AD Explorer tool (http://technet.microsoft.com/en-us/sysinternals/bb963907.aspx) for understanding how your AD and your paths in LDAP look like
marc_s