Guest User

PasswordReminder.vbs

a guest
May 11th, 2018
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. '==========================================
  2. ' Check for password expiring notification
  3. '==========================================
  4. ' First, get the domain policy.
  5. '==========================================
  6. Dim oDomain
  7. Dim oUser
  8. Dim maxPwdAge
  9. Dim numDays
  10. Dim warningDays
  11.  
  12. warningDays = 14
  13.  
  14. Set LoginInfo = CreateObject("ADSystemInfo")
  15. Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")
  16. strDomainDN = UCase(LoginInfo.DomainDNSName)
  17. strUserDN = LoginInfo.UserName
  18.  
  19. '========================================
  20. ' Check if password is non-expiring.
  21. '========================================
  22. Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
  23. intUserAccountControl = objUser.Get("userAccountControl")
  24. If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
  25. 'WScript.Echo "The password does not expire."
  26. Else
  27.  
  28. Set oDomain = GetObject("LDAP://" & strDomainDN)
  29. Set maxPwdAge = oDomain.Get("maxPwdAge")
  30.  
  31. '========================================
  32. ' Calculate the number of days that are
  33. ' held in this value.
  34. '========================================
  35. numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
  36. maxPwdAge.LowPart) / CCur(-864000000000)
  37. 'WScript.Echo "Maximum Password Age: " & numDays
  38.  
  39. '========================================
  40. ' Determine the last time that the user
  41. ' changed his or her password.
  42. '========================================
  43. Set oUser = GetObject("LDAP://" & strUserDN)
  44.  
  45. '========================================
  46. ' Add the number of days to the last time
  47. ' the password was set.
  48. '========================================
  49. whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
  50. fromDate = Date
  51. daysLeft = DateDiff("d",fromDate,whenPasswordExpires)
  52.  
  53. 'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged
  54.  
  55. if (daysLeft < warningDays) and (daysLeft > -1) then
  56. Msgbox "Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Once logged in, press CTRL-ALT-DEL and select the 'Change a password' option", 0, "Password Expiration Warning!"
  57. End if
  58.  
  59. End if
  60.  
  61. '========================================
  62. ' Clean up.
  63. '========================================
  64. Set oUser = Nothing
  65. Set maxPwdAge = Nothing
  66. Set oDomain = Nothing
Advertisement
Add Comment
Please, Sign In to add comment