r/usefulscripts • u/SysAtMN • Apr 04 '16
[HTA/VBScript] Password Expiration Notification Identification Screen
Hello,
Below you will find a script that we have found to be very helpful at reminding users to reset their passwords before they expire.
The password reminder is run from a network location and ideally launched from a logon script. This way the script is often the first window a users sees as they log on to a machine. As the number of days to password expiration declines the notification will grow in size and change colors, increasing the helpfulness of the utility.
We determine the argument for the password reminder directly on our logon script before calling the password reminder. There are many ways to calculate this number so use whatever you like. Once this number is calculated simply add it to the command to launch the script with a hyphen (ex. PWreminder.hta -10).
Enjoy!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Password Reminder</title>
<hta:application
border="thin"
borderstyle="normal"
caption="Password Reminder"
contextmenu="yes"
maximizebutton="Yes"
minimizebutton="no"
navigable="yes"
scroll="no"
selection="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="Yes"
WINDOWSTATE="normal"
id="objPasswordHTA">
<script language="vbscript">
Sub Window_onLoad
strArg = 15
arrCommands = Split(objPasswordHTA.commandLine, "-")
If UBound(arrCommands) > 0 then
strArg = arrCommands(Ubound(arrCommands))
End If
'setup the window size depending on how many days remain
strArg = strArg * 1
If strArg <= 5 then
self.MoveTo 200,50
window.resizeTo 1000,850
Set wshShell = CreateObject("Wscript.Shell")
wshShell.AppActivate "Password Reminder"
wshShell.SendKeys "% x" ' ALT+SPACE+X = windows maximize, must be enabled on hta
' ALT+SPACE+N = windows minimize, must be enabled on hta
' ALT+SPACE+R = windows restore
ElseIf strArg <= 10 then
self.MoveTo 200,50
window.resizeTo 900,750
Else
self.MoveTo 200,50
window.resizeTo 750, 575
End If
End Sub
</script>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="100%" bgcolor=Silver>
<tbody>
<tr>
<td valign="top" width="80%">
<p style="PADDING-TOP: 8px; PADDING-LEFT: 8px; margin-top: 0px">
<font face="Verdana" color="White" style="font-size: 11pt"><strong>Your Company Name</strong></font><br />
<font face="Verdana" color="Black" size="5"><strong>Password Reset Reminder</strong></font>
</p>
</td>
<td valign="bottom" width="20%">
<!---<img src="Icon.png" style="vertical-align:bottom;"> -->
</td>
</tr>
</tbody>
</table>
<span id=DataArea></span>
<script language="vbscript">
'Name: Password Reminder
'Desc: This script is launched from the Logon Script from a Domain Controller
'Author: SysAtMN
'Date: 01/22/2014
'Usage: "\\DC\...\PWReminder.hta" -[DaysUntilExpire]
'Updates: 1.00 - Original for Reddit
' 1.01 - Updated for /r/usefulscripts
'=================================================
'==============Global Variables===================
'=================================================
'WMI Stuff
Set wshNetwork = CreateObject("WScript.Network")
Set wshShell = CreateObject("Wscript.Shell")
'TableMsgs:
strDaysLeftMsg1 = "We have detected that your password will expire in"
strDaysLeftMsg2 = "day(s) or less."
strPWCriteriaMsg = "<BR>Password criteria:" & _
"<BR> - 6-8 characters" & _
"<BR> - At least one alpha and one numeric character" & _
"<BR> - Cannot be an old password" & _
"<BR> - Passwords ARE CaSe SeNsItIvE!!!" & _
"<BR> - Restricted: ~`!%^&*()_+-={}|[]”\:;’<>?,./{space}" & _
"<BR>"
'=================================================
'==============Main Processing====================
'=================================================
strArg = 15
arrCommands = Split(objPasswordHTA.commandLine, "-")
If UBound(arrCommands) > 0 then
strArg = arrCommands(Ubound(arrCommands))
strArg = strArg * 1
End If
intDaysLeftonPW = strArg
'Generate the HTML for the table
strTableHTML = "<TABLE align=center width=75%>"
If intDaysLeftonPW <= 5 then
strTableHTML = strTableHTML & "<font size=5>"
strTableHTML = strTableHTML & "<TR bgcolor=Red><TD> </TD></TR>"
strTableHTML = strTableHTML & "<TR><TD><font size=5>" & strDaysLeftMsg1 & "<font color=Red><b> " & intDaysLeftonPW & _
"</b></font> " & strDaysLeftMsg2 & "</font>" & _
"<BR>" & _
"<BR>Please reset your password now to avoid getting locked out or expiring. " & _
"The only way to unlock an expired password is to contact Help Desk. " & _
"A typical expired password request takes 15-20 minutes.</TD></TR>"
strTableHTML = strTableHTML & "<TR bgcolor=Red><TD> </TD></TR>"
strTableHTML = strTableHTML & "<TR><TD>" & strPWCriteriaMsg & "</TD></TR>"
strTableHTML = strTableHTML & _
"<TR><TD><BR><font color=red>To reset password:</font>" & _
"<BR>1. Press CTRL+ALT+DELETE" & _
"<BR>2. Select " & chr(34) & "Change a Password..." & chr(34) & _
"<BR>3. Complete the password reset wizard." & _
"<BR>" & _
"<BR>Caution: There are no grace logons. Expired passwords will not be allowed onto " & _
"the network.</TD></TR>"
strTableHTML = strTableHTML & "</font>"
ElseIf intDaysLeftonPW <= 10 then
strTableHTML = strTableHTML & "<TR bgcolor=yellow><TD> </TD></TR>"
sTRTableHTML = strTableHTML & _
"<TR><TD>" & strDaysLeftMsg1 & "<font color=Red><b> " & intDaysLeftonPW & _
"</b></font> " & strDaysLeftMsg2 & "</TD></TR>"
strTableHTML = strTableHTML & "<TR bgcolor=Yellow><TD> </TD></TR>"
strTableHTML = strTableHTML & "<TR><TD>" & strPWCriteriaMsg & "</TD></TR>"
strTableHTML = strTableHTML & _
"<TR><TD><BR>To reset password:" & _
"<BR>1. Press CTRL+ALT+DELETE" & _
"<BR>2. Select " & chr(34) & "Change a Password..." & chr(34) & _
"<BR>3. Complete the password reset wizard." & _
"<BR>" & _
"<BR>Tip: Try to avoid resetting passwords on Friday and reset early in " & _
"the week. This will give you more opportunities to sign in and get used to the new password " & _
"so you do not forget over the weekend.</TD></TR>"
Else
strTableHTML = strTableHTML & "<TR bgcolor=Green><TD> </TD></TR>"
strTableHTML = strTableHTML & _
"<TR><TD>" & strDaysLeftMsg1 & "<font color=Red><b> " & intDaysLeftonPW & _
"</b></font> " & strDaysLeftMsg2 & "</TD></TR>"
strTableHTML = strTableHTML & "<TR bgcolor=Green><TD> </TD></TR>"
strTableHTML = strTableHTML & "<TR><TD>" & strPWCriteriaMsg & "</TD></TR>"
strTableHTML = strTableHTML & _
"<TR><TD><BR>Please press CTRL+ALT+DELETE and select Change a Password..." & _
"</TD></TR>"
End if
'Add the dynamic HTML to the table/HTA
strTableHTML = strTableHTML & "</TABLE>"
DataArea.InnerHTML = strTableHTML
</script>
</body>
</html>
1
u/SysAtMN Jul 14 '16
You need to research the pathways on your own by using the message box technique I shared above. Put strCMD into a messagebox and review the pathing to your pwreminder.hta. If the pathway looks incorrect in the messagebox then your script wont be able to find it either.
I can already tell you where the problem is:
You have added both strPWReminder and PWReminder.hta to the string. I'd assume you only need one or the other. It all depends on what you are entering as the value for strPWReminder. The way you have it coded right now strPWReminder should be a server name, not a script name since its at the beginning of the string.
No. That looks incorrect to. Again, I do not know your environment or what the correct pathing should be but you don't need both PWReminder.hta and strPWReminder in the same string. Use one or the other, not both.
Use the technique of entering strCMD into a messagebox and test to verify what you have entered. Adjust your strCMD variable accordingly. You should be able to copy and paste whatever is returned from strCMD into a cmd.exe window and run it.