Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello guys

Is there any other way to find out the password expiration date of the user "testi"?
I tried this:
using (var userEntry = new DirectoryEntry(configurationProvider.Configuration.DomainName + ",testi")
{
  var passwordExpDate = userEntry.InvokeGet("PasswordExpirationDate");
}

I appreciate every help.

Best regards
v_tigra
Posted
Updated 4-Jan-16 3:26am
v2
Comments
ZurdoDev 4-Jan-16 9:28am    
Does the code work?
BillWoodruff 4-Jan-16 10:15am    
Error message ?

1 solution

Try like this way:
C#
public static DateTime GetPasswordExpirationDate(string userId, string domainOrMachineName)
{
    using (var userEntry = new DirectoryEntry("WinNT://" + domainOrMachineName + '/' + userId + ",user"))
    {
        return userEntry.InvokeGet("PasswordExpirationDate");
    }
}
 
Share this answer
 
Comments
Maciej Los 4-Jan-16 15:47pm    
Quite possible "cannot implicitly convert object to System.DateTime" error.
On the second hand: 5!

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