-1

Found this file on a unit at work...

Set WshShell = CreateObject("WScript.Shell")
PINGFlag = Not CBool(WshShell.run("ping contoso.com -n 1 " & vSystemIdentifier,0,True))
      If PINGFlag = True Then
         'Successful ping
    'WScript.Echo "Connectivity to domain confirm."
    Call Password
      Else
         'Unsuccessful ping
    'WScript.Echo "No Connectivity to domain password check cancelled."
      End If



Function Password()

'========================================
    ' First, get the domain policy.
    '========================================
    Dim oDomain
    Dim oUser
    Dim maxPwdAge
    Dim numDays
    Dim warningDays

    warningDays = 15

    Set LoginInfo = CreateObject("ADSystemInfo")  
    Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")  
    strDomainDN = UCase(LoginInfo.DomainDNSName) 
    strUserDN = LoginInfo.UserName


    Set oDomain = GetObject("LDAP://" & strDomainDN)
    Set maxPwdAge = oDomain.Get("maxPwdAge")

    '========================================
    ' Calculate the number of days that are
    ' held in this value.
    '========================================
    numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
                    maxPwdAge.LowPart) / CCur(-864000000000)
    'WScript.Echo "Maximum Password Age: " & numDays

    '========================================
    ' Determine the last time that the user
    ' changed his or her password.
    '========================================
    Set oUser = GetObject("LDAP://" & strUserDN)

    '========================================
    ' Add the number of days to the last time
    ' the password was set.
    '========================================
    whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
    fromDate = Date
    daysLeft = DateDiff("d",fromDate,whenPasswordExpires)

    'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged

    if (daysLeft < warningDays) and (daysLeft > -1) then
        Msgbox "Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Press CTRL-ALT-DEL and" & chr(13) & "select the 'Change a password' option" & chr(13) & "Please allow enough time for password change to take effect," & chr(13) & "minimum of 15 minutes before disconnecting", 0, "PASSWORD EXPIRATION WARNING!"
    End if

    '========================================
    ' Clean up.
    '========================================
    Set oUser = Nothing
    Set maxPwdAge = Nothing
    Set oDomain = Nothing
End Function
6
  • 2
    Have you asked your local IT staff the purpose of the script? Or are you local IT and you're wondering why this script is on the computers you support? Commented Oct 18, 2018 at 23:38
  • 1
    It appears to just be a script to notify users of when their password is about to expire so they can potentially change it before becoming locked out of their accounts. My guess is that it is scheduled to run the script either at login or on constantly in the background.
    – Jesse P.
    Commented Oct 18, 2018 at 23:46
  • Wondering why it is on the computers. There is no login to these units as they are always running. Trying to clean them up a bit so not so much clutter and came across this. Appreciate the information.
    – Alex
    Commented Oct 19, 2018 at 0:48
  • @Alex - Unless the accounts have no password, they have a password, and that means the password expires just like any account. The funniest thing about the script is the fact, Windows, already does a notification when the password is about to expire
    – Ramhound
    Commented Oct 19, 2018 at 1:29
  • 2
    @Alex The reason this script is needed is because those computers are always logged in. Windows only notifies a user that their password will expire when they log on. Commented Oct 19, 2018 at 11:01

1 Answer 1

5

This script creates a popup to warn a user when their password is going to expire.

It was originally posted by MarkK/Mark-K as responses to posts on both Server Fault and on Microsoft's TechNet Forums, both of which have received updates since the version you've posted. The version you've included in your question also includes some modifications not present in the versions Mark K posted.

For reference, here is a link to the relevant Server Fault answer, and both the Original & Update posts on the TechNet Forums.

Also, I found a screenshot of the popup this script produces posted by JitenSh on the Spiceworks forums:
Password Expiration Warning:   ( i )   Your password will expire in 4 day(s) at 4/10/2014 2:03:42 PM   Press CTRL + ALT + DEL and select the "Change a password" option.   [OK]

1
  • Note: I found all this information with a simple web search for a short section of the code.
    – 3D1T0R
    Commented Oct 19, 2018 at 1:06

Not the answer you're looking for? Browse other questions tagged .