'* PWDTIME.VBS '* Mike Kanofsky '* University of Florida Active Directory Team '* mikekano@ufl.edu '* 5-12-04 '* ver 1.04 '* Displays information when user password is about to expire based on '* GLpwdExpired extended schema attribute in UFAD On Error Resume Next 'set some constants intNoticeDays = 360 'Number of days before password expires to give user message 'intNoticeDays = 14 'Number of days before password expires to give user message 'Create Objects Set objRootDSE = GetObject("LDAP://rootDSE") 'Get's AD root information Set objSysInfo = CreateObject("ADSystemInfo") 'Creates object for AD information Set objUser = GetObject("LDAP://" & objSysInfo.UserName) 'User's DN set WshShell=Wscript.CreateObject("Wscript.Shell") set oShell = CreateObject("WScript.Shell") ' Examples of other attributes 'wscript.echo objSysInfo 'wscript.echo objUser ' wscript.echo "User's DN: " & objsysinfo.username ' wscript.echo "Username: " & objItem.Get("sAMAccountName") ' wscript.echo "User: " & objUser.Get("DisplayName") ' wscript.echo "User's Title: " & objUser.Get("title") ' wscript.echo "title:" & objUser.title 'wscript.echo objUser.Get("GLPwdExpired") 'wscript.echo objUser.GLPwdExpired 'Split users Password Last Changed date into components dtmADPwdSet = objUser.PasswordLastChanged dtmPwdSetDate = PwdSetDate(dtmADPwdSet) dtmPwdSetTime = PwdSetTime(dtmADPwdSet) 'check GLpwdExpired to see if it exists and split into sections dtmGLPwdExpired = objUser.Get("GLPwdExpired") dtmGLPwdExpiredDate = datevalue(left(dtmGLPwdExpired,10)) if isdate(dtmGLPwdExpiredDate) then strGLPwdExpiredValid = "true" else strGLPwdExpiredValid = "false" end if if dtmGLPwdExpired = "" then wscript.echo "password expiration not synced. Expiration time will be synced the next time password is changed." end if if strGLPwdExpiredValid = "true" then dtmGLPwdExpDate = left(objUser.GLPwdExpired,10) dtmGLPwdExpTime = right(objUser.GLPwdExpired,8) 'calculate # of days before password expires. dtmToday = FormatDateTime(Now(),2) dtmExpires = DateValue(FormatDateTime(Now(),2))-DateValue(Left(dtmGLPwdExpired,10)) dtmExpiredays = datediff("d",now,dtmGLPwdExpDate) Else If Err.Number <> 0 Then If Err.Number = "-2147463155" Then dtmGLPwdExpired = "Not Set" Else dtmGLPwdExpired = "Unknown Error: " & Err.Number End If ' Err.Number = "-2147463155" Else End If ' err.number <> 0 end if ' dtmGLPwdExpired <> "" '-------- intIcon = VBInformation if (dtmExpiredays = 0) and (strGLPwdExpiredValid = "true") then ' "password has expired" PwdChangeNow () intIcon = vbCritical else if (dtmExpiredays <= intNoticeDays) and (strGLPwdExpiredValid = "true") then ' "password will expire soon" PwdChangeSoon () end if ' dtmExpiredays <= intNoticeDays End If 'dtmExpiredays = 0 then 'Define text for message box 'wscript.echo "end of script.........." ' remove objects Set objRootDSE = Nothing Set objSysInfo = Nothing Set objUser = Nothing set WshShell = Nothing set oshell = Nothing '*********************************** 'Split users Password Last Changed date into components Function PwdSetDate (varADPwdSet) dtmPwdSetYear = datepart("yyyy",varADPwdSet) dtmPwdSetMonth = datepart("m",varADPwdSet) dtmPwdSetDay = datepart("d",varADPwdSet) 'reformat date into mm/dd/yyyy from above components PwdSetDate = dtmPwdSetMonth & "/" & dtmPwdSetDay &"/" & dtmPwdSetYear End Function Function PwdSetTime (dtmADPwdSet) dtmPwdSetHour = datepart("h",objUser.PasswordLastChanged) dtmPwdSetMin = datepart("n",objUser.PasswordLastChanged) dtmPwdSetSec = datepart("s",objUser.PasswordLastChanged) 'reformat Time to HH:MM:SS PwdSetTime = dtmPwdSetHour & ":" & dtmPwdSetMin &":" & dtmPwdSetSec End Function Function PwdChangeSoon () ' wscript.echo "dtmExpireDays " & dtmExpireDays & "intNoticeDays:" & intNoticeDays & " inticon: " & inticon strMsg = "Your GatorLink password will expire in " & dtmExpiredays & " days on: " & dtmGLPwdExpDate & " at " & dtmGLPwdExpTime strMsgPwdSetTime= "You last set your GatorLink password on " & dtmPwdSetDate & " at " & dtmPwdSetTime strResetPass="Would you like to reset your password now at my.ufl.edu?" ' wscript.echo strMsg & vbCrLf & strMsgPwdSetTime strMsgfull = strMsg & vbCrLf & strMsgPwdSetTime & vbCrLf &vbCrLf & strResetPass intBoxType=vbYesNo + intIcon + vbDefaultButton2 varMsgBox = wshShell.Popup(strMsgfull,5,"Password Expiration",intBoxType) Select Case varMsgBox Case vbYes oShell.Run "http://my.ufl.edu/psp/ps/EMPLOYEE/UF_PA_SSL/c/MAINTAIN_SECURITY.CHANGE_PASSWORD.GBL" Case vbNo strMsgRemind = "Remember that you will need to reset your password at http://my.ufl.edu before it expires" varMsgBox = wshShell.Popup(strMsgRemind,5,"Reminder",vbInformation) End Select End Function ' Function PwdChangeNow () '* called when password expires in 0 days '* will redirect to GL password change page strMsg = "Your GatorLink password has expired! You will be redirected to my.ufl.edu to reset it." varPopupBox = wshShell.Popup(strMsg,3,"redirecting to my.ufl.edu...", vbExclamation) oShell.Run "http://my.ufl.edu/psp/ps/EMPLOYEE/UF_PA_SSL/c/MAINTAIN_SECURITY.CHANGE_PASSWORD.GBL" End Function