Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used the class in System.DirectoryServices to change password in AD. The code like this:
C#
DirectoryEntry _directoryEntry = new DirectoryEntry(ldapPath, user, pwd, AuthenticationTypes.Secure);
    public bool ChangePassword(string userPath, string newPassword)
    {
        try
        {
            if (userPath != null && _directoryEntry != null)
            {
                _directoryEntry.Path = userPath;
                //Set the password
                _directoryEntry.Invoke("SetPassword", new object[] { newPassword });
                _directoryEntry.CommitChanges();
                return true;
            }
        }
        catch (Exception ex)
        {
            //Invalid Login or the domain controller is not contactable
            throw ex;
        }
        finally
        {
            _directoryEntry.Close();
            _directoryEntry = null;
        }
        return false;
    }


I executed these codes on different computer. The time spent from several ms to several seconds.

why does the same code executed in different Environment to change password in AD spent different time? I have spent a lot of time in dealing this problem but still no result. Can anybody tell me? Thank you very much!!!!!
Posted

1 solution

 
Share this answer
 
Comments
Prince2605 26-Mar-12 3:14am    
Yes. The problem likes this. But there is no solution.
Roman Lerman 26-Mar-12 3:22am    
There's nothing to do with execution time.
You may try to run it in background.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900