密码通知脚本引发“类型不匹配".剩余天数错误 [英] Password notification script raising "type mismatch" error for remaining number of days

查看:93
本文介绍了密码通知脚本引发“类型不匹配".剩余天数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让每个人自己工作,但不能让他们一起工作,登录脚本使用strArg =调用HTA文件,HTA文件生成一个密码窗口.当登录脚本运行HTA文件错误时,第31和106行就会出现错误.

I can get each one to work by themselves but I can not get them to work together, the logon script uses the strArg = to call on the HTA file, the HTA file generates a password window. When the logon script runs the HTA file errors out on lines 31 and 106.

我知道问题出在strArg之内,我无法解决.它应在标记过期前的13天通知最终用户.任何帮助将是巨大的.目前,就像脚本一样,我的HTA文件部分出现错误:

I know the issue lies within the strArg, I can not figure it out. It should be notifying endusers at the 13 days before expiring mark. Any help would be great. Currently, as the script is now, I get an error with the HTA file part:

第31和106行
错误:类型不匹配'strARG'
代码:0

Line: 31 and 106
Error: Type Mismatch 'strARG'
code: 0

我确实在下面的链接中打开了问题,但是那些建议并不能解决问题.

I did open the question in the link below but those suggestions did not solve the problem.

vbscript语句不匹配排序失败

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 And ADS_UF_DONT_EXPIRE_PASSWD Then
  'WScript.Echo "The password does not expire."
Else
  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

  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) And (daysLeft > -1) Then
    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 

HTA文件:

<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 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>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 that your password will expire in"
strDaysLeftMsg2  = "day(s) or less."
strPWCriteriaMsg = "<BR>Password criteria:" & _
                   "<BR> - 8 characters or longer" & _
                   "<BR> - At least one alpha, one numeric, and one special character" & _
                   "<BR> - Cannot be an old password" & _
                   "<BR> - Passwords ARE CaSe SeNsItIvE!!!" & _
                   "<BR>"

strArg = 13
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>&nbsp;</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>&nbsp;</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>&nbsp;</TD></TR>"
  sTRTableHTML = strTableHTML & _
                 "<TR><TD>" & strDaysLeftMsg1 & "<font color=Red><b> " & intDaysLeftonPW & _
                 "</b></font> " & strDaysLeftMsg2 & "</TD></TR>"
  strTableHTML = strTableHTML & "<TR bgcolor=Yellow><TD>&nbsp;</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>&nbsp;</TD></TR>"
  strTableHTML = strTableHTML & _
                 "<TR><TD>" & strDaysLeftMsg1 & "<font color=Red><b> " & intDaysLeftonPW & _
                 "</b></font> " & strDaysLeftMsg2 & "</TD></TR>"
  strTableHTML = strTableHTML & "<TR bgcolor=Green><TD>&nbsp;</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>

推荐答案

有罪魁祸首:

strCMD =  "\\domain\netlogon\PwExpChk\PWReminder.hta" & " -" & intDaysRemaining
'                                                              ~~~~~~~~~~~~~~~~

您永远不会在代码中的任何位置定义intDaysRemaining,因此变量为空,这意味着您的命令行如下所示:

You never define intDaysRemaining anywhere in your code, so the variable is empty, meaning your commandline looks like this:

\\domain\netlogon\PwExpChk\PWReminder.hta -

-处拆分此命令行会在最后一个字段中为您提供一个带有空字符串的数组,这反过来会引发您尝试将空字符串与1乘以时所观察到的错误.

Splitting this commandline at - gives you an array with an empty string in the last field, which in turn raises the error you observed when you try to multiplicate an empty string with 1.

演示:

>>> cmdline = "\\domain\netlogon\PwExpChk\PWReminder.hta -"
>>> a = Split(cmdline, "-")
>>> v = a(UBound(a))
>>> WScript.Echo "_" & v & "_"
__
>>> i = v * 1
Type mismatch (0xD)

如果您将Option Explicit添加到VBScript中,或者至少在调试时(MsgBox objPasswordHTA.commandLine)费心地在HTA中回显命令行,您会立刻发现这一点.

You would have spotted this right away had you added Option Explicit to your VBScript, or at least bothered to echo the commandline in your HTA when debugging (MsgBox objPasswordHTA.commandLine).

这篇关于密码通知脚本引发“类型不匹配".剩余天数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆