Microsoft KB Archive/323750

= How to obtain password expiration date by using LDAP ADSI provider =

Article ID: 323750

Article Last Modified on 5/19/2005

-

APPLIES TO


 * Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
 * Microsoft Windows Server 2003, Standard Edition (32-bit x86)
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Service Pack 3
 * Microsoft Windows 2000 Service Pack 2
 * Microsoft Windows 2000 Service Pack 1
 * Microsoft Windows XP Professional
 * Microsoft Active Directory Service Interfaces 2.5
 * Microsoft Active Directory Service Interfaces 2.5

-



This article was previously published under Q323750



SUMMARY
This article contains sample code that demonstrates how to use the LDAP ADSI provider to obtain the password expiration date of an Active Directory user.



MORE INFORMATION
This article contains sample code for the following programs:
 * Visual Basic
 * VBScript

Visual Basic Sample Code
To use the following Visual Basic sample code, you must add Active DS Type Library to your Project's reference. '========================================   ' First, get the domain policy. '========================================   Dim oDomain As IADsContainer Dim oUser As IADsUser Dim maxPwdAge As LargeInteger '========================================   ' Declaring numDays as Currency, due to a    ' large number calculation. '========================================   Dim numDays As Currency strDomainDN = &quot;YOURDOMAIN&quot; strUserDN = strDomainDN & &quot;/CN=John Doe,CN=Users,DC=YOURDOMAIN,DC=COM&quot; Set oDomain = GetObject(&quot;LDAP://&quot; & strDomainDN) Set maxPwdAge = oDomain.Get(&quot;maxPwdAge&quot;)

'========================================   ' Calculate the number of days that are ' held in this value. '========================================   numDays = ((maxPwdAge.HighPart * 2 ^ 32) + _                maxPwdAge.LowPart) / -864000000000@ Debug.Print &quot;Maximum Password Age: &quot; & numDays '========================================   ' Determine the last time that the user ' changed his or her password. '========================================   Set oUser = GetObject(&quot;LDAP://&quot; & strUserDN)

'========================================   ' Add the number of days to the last time ' the password was set. '========================================   whenPasswordExpires = DateAdd(&quot;d&quot;, numDays, oUser.PasswordLastChanged) Debug.Print &quot;Password Last Changed: &quot; & oUser.PasswordLastChanged Debug.Print &quot;Password Expires On: &quot; & whenPasswordExpires

'========================================   ' Clean up. '========================================   Set oUser = Nothing Set maxPwdAge = Nothing Set oDomain = Nothing

VBScript Sample Code
To use the following sample you code, you must copy the code to a text file with a .vbs file extension. '========================================   ' First, get the domain policy. '========================================   Dim oDomain Dim oUser Dim maxPwdAge Dim numDays strDomainDN = &quot;YOURDOMAIN&quot; strUserDN = strDomainDN & &quot;/CN=John Doe,CN=Users,DC=YOURDOMAIN,DC=COM&quot; Set oDomain = GetObject(&quot;LDAP://&quot; & strDomainDN) Set maxPwdAge = oDomain.Get(&quot;maxPwdAge&quot;)

'========================================   ' Calculate the number of days that are ' held in this value. '========================================   numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _                    maxPwdAge.LowPart) / CCur(-864000000000) WScript.Echo &quot;Maximum Password Age: &quot; & numDays '========================================   ' Determine the last time that the user ' changed his or her password. '========================================   Set oUser = GetObject(&quot;LDAP://&quot; & strUserDN)

'========================================   ' Add the number of days to the last time ' the password was set. '========================================   whenPasswordExpires = DateAdd(&quot;d&quot;, numDays, oUser.PasswordLastChanged) WScript.Echo &quot;Password Last Changed: &quot; & oUser.PasswordLastChanged WScript.Echo &quot;Password Expires On: &quot; & whenPasswordExpires

'========================================   ' Clean up. '========================================   Set oUser = Nothing Set maxPwdAge = Nothing Set oDomain = Nothing

WScript.Echo &quot;Done&quot;

