public static DateTime PasswordExpireTime(string domainOrMachineName, string userName)
 {
     using (var directoryEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + domainOrMachineName + '/' + userName + ",user"))
     {
         try
         {
             return (DateTime)directoryEntry.InvokeGet("PasswordExpirationDate");
         }
         catch (TargetInvocationException e)
         {
             throw e.InnerException;
         }
     }
 }