vbscript - Password notification script raising "type mismatch" error for remaining number of days -
i can each 1 work can not them work together, logon script uses strarg =
call on hta file, hta file generates password window. when logon script runs hta file errors out on lines 31 , 106.
i know issue lies within strarg
, can not figure out. should notifying endusers @ 13 days before expiring mark. great. currently, script now, error hta file part:
line: 31 , 106
error: type mismatch 'strarg'
code: 0
i did open question in link below suggestions did not solve problem.
vbscript statement mismatch sring failing
dim odomain dim ouser dim maxpwdage dim numdays dim warningdays warningdays = 13 set logininfo = createobject("adsysteminfo") set objuser = getobject("ldap://" & logininfo.username & "") strdomaindn = ucase(logininfo.domaindnsname) struserdn = logininfo.username const ads_uf_dont_expire_passwd = &h10000 intuseraccountcontrol = objuser.get("useraccountcontrol") if intuseraccountcontrol , ads_uf_dont_expire_passwd 'wscript.echo "the password not expire." else set odomain = getobject("ldap://" & strdomaindn) set maxpwdage = odomain.get("maxpwdage") ' calculate number of days held in value. numdays = ccur((maxpwdage.highpart * 2 ^ 32) + _ maxpwdage.lowpart) / ccur(-864000000000) 'wscript.echo "maximum password age: " & numdays set ouser = getobject("ldap://" & struserdn) whenpasswordexpires = dateadd("d", numdays, ouser.passwordlastchanged) fromdate = date daysleft = datediff("d", fromdate, whenpasswordexpires) 'wscript.echo "password last changed: " & ouser.passwordlastchanged if (daysleft < warningdays) , (daysleft > -1) strcmd = "\\domain\netlogon\pwexpchk\pwreminder.hta" & " -" & intdaysremaining set wshshell = createobject("wscript.shell") rc = wshshell.run(strcmd , 0, false) end if end if set ouser = nothing set maxpwdage = nothing set odomain = nothing set wshshell = nothing
the hta file:
<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 = 13 arrcommands = split(objpasswordhta.commandline, "-") if ubound(arrcommands) > 0 strarg = arrcommands(ubound(arrcommands)) end if 'setup window size depending on how many days remain strarg = strarg * 1 if strarg <= 5 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 enabled on hta ' alt+space+n = windows minimize, must enabled on hta ' alt+space+r = windows restore elseif strarg <= 10 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>company name</strong></font><br /> <font face="verdana" color="black" size="5"><strong>password reset reminder</strong></font> <p> </td> <td valign="bottom" width="50%"> <img src='\\domain\netlogon\pwexpchk\logo.jpg' width='451' height='170' style="vertical-align:bottom;"> </td> </tr> </tbody> </table> <span id=dataarea></span> <script language="vbscript"> set wshnetwork = reateobject("wscript.network") set wshshell = createobject("wscript.shell") 'tablemsgs: strdaysleftmsg1 = "we have detected password expire in" strdaysleftmsg2 = "day(s) or less." strpwcriteriamsg = "<br>password criteria:" & _ "<br> - 8 characters or longer" & _ "<br> - @ least 1 alpha, 1 numeric, , 1 special character" & _ "<br> - cannot old password" & _ "<br> - passwords case sensitive!!!" & _ "<br>" strarg = 13 arrcommands = split(objpasswordhta.commandline, "-") if ubound(arrcommands) > 0 strarg = arrcommands(ubound(arrcommands)) strarg = strarg * 1 end if intdaysleftonpw = strarg 'generate html table strtablehtml = "<table align=center width=75%>" if intdaysleftonpw <= 5 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 password avoid getting locked out or expiring. " & _ "the way unlock expired password contact 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 password..." & chr(34) & _ "<br>3. complete password reset wizard." & _ "<br>" & _ "<br>caution: there no grace logons. expired passwords not allowed onto " & _ "the network.</td></tr>" strtablehtml = strtablehtml & "</font>" elseif intdaysleftonpw <= 10 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 password..." & chr(34) & _ "<br>3. complete password reset wizard." & _ "<br>" & _ "<br>tip: try avoid resetting passwords on friday , reset in " & _ "the week. give more opportunities sign in , used new password " & _ "so not forget on 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 , select change password..." & _ "</td></tr>" end if 'add dynamic html table/hta strtablehtml = strtablehtml & "</table>" dataarea.innerhtml = strtablehtml </script> </body> </html>
there culprit:
strcmd = "\\domain\netlogon\pwexpchk\pwreminder.hta" & " -" & intdaysremaining ' ~~~~~~~~~~~~~~~~
you never define intdaysremaining
anywhere in code, variable empty, meaning commandline looks this:
\\domain\netlogon\pwexpchk\pwreminder.hta -
splitting commandline @ -
gives array empty string in last field, in turn raises error observed when try multiplicate empty string 1.
demonstration:
>>> cmdline = "\\domain\netlogon\pwexpchk\pwreminder.hta -" >>> a = split(cmdline, "-") >>> v = a(ubound(a)) >>> wscript.echo "_" & v & "_" __ >>> i = v * 1 type mismatch (0xd)
you have spotted right away had added option explicit
vbscript, or @ least bothered echo commandline in hta when debugging (msgbox objpasswordhta.commandline
).
Comments
Post a Comment