Error in the userEntry.Invoke

0

I have a code to change the passwords of the active directory from the web, it seems good, but when executing and debugging the code, in the line of userEntry.invoke goes by catch and the exception says: "

  

An exception occurred in the destination of the invocation "and the   InnerException = {"The member was not found. (Exception   HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND)) "}

and does not change the password.

Method code:

DirectoryEntry directoryEntry = new DirectoryEntry(ldaPath, domainName+"\"+ userName, Password);

if (directoryEntry != null)
{
    DirectorySearcher searchEntry = new DirectorySearcher(directoryEntry);
    searchEntry.Filter = "(SAMAccountname=" + userName + ")";
    SearchResult result = searchEntry.FindOne();
    if (result != null)
    {
        DirectoryEntry userEntry = result.GetDirectoryEntry();
        if (userEntry != null)
        {
            userEntry.Invoke("SetPassword", new object[] { newPassword });
            userEntry.Properties["lockouttime"].Value = 0;
        }
    }
}

But I do not know how to solve it. How to solve this exception?

    
asked by Jhohan David 16.08.2018 в 21:56
source

0 answers