在VBSCript中输出msgbox时遇到问题

时间:2014-06-10 10:28:28

标签: vbscript

我正在运行一个脚本,在运行程序之前在Windows机器上执行多项检查。我正在运行VBScript来检查补丁状态,防火墙状态和防病毒状态等内容。脚本运行后,需要输出信息,以便最终用户可以解决出现的任何问题。这需要在单个消息框中输出,该消息框显示最终用户计算机上不符合的所有内容。

现在脚本运行后,我得到多个输出框,但没有一个显示需要修复的名称。我只是在对话框中的引号中获取信息。

errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix

For Each item In errors
    set errorfix = errorfix & item & vbnewline
    if (errors = "Off") Then
        msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
        "The following requires attention" & vbNewLine & errorfix & vbNewLine & _
        "Press OK to Continue", 0, "Moka 5 Compliance Check"
    Else
        msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
        "Everything looks good." & vbNewLine & vbNewLine & _
        "Press OK to Continue", 0, "Moka 5 Compliance Check"
    End if
Next

非常感谢任何帮助

2 个答案:

答案 0 :(得分:1)

我认为您需要为msgbox投放回复,即tempresponse = Msgbox("") Link is here

errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix, tempresponse

For Each item In errors
    set errorfix = errorfix & item & vbnewline
    if (errors = "Off") Then
        tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
        "The following requires attention" & vbNewLine & errorfix & vbNewLine & _
        "Press OK to Continue", 0, "Moka 5 Compliance Check")
    Else
        tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
        "Everything looks good." & vbNewLine & vbNewLine & _
        "Press OK to Continue", 0, "Moka 5 Compliance Check")
    End if
Next

正如@Tomalak在每次迭代后所说,您需要清除msgbox,popup work better, as it will clear the message after x seconds.

答案 1 :(得分:1)

我的建议是完全避免使用数组,而是使用更方便的dictionaries

如果没有别的东西你会以这种方式创建更多可读代码,但它们也比数组更强大。

Option Explicit

Dim errors
Set errors = CreateObject("Scripting.Dictionary")

' fill the dictionary troughout your program. Fill in just the 
' actionables and don't insert the stuff that's okay.
errors("Firewall Status") = "Off"
errors("This other thing") = "Missing"

If errors.Count = 0 Then
    MsgBox "Compliance Check results" & vbNewLine & vbNewLine & _
           "Everything looks good." & vbNewLine & vbNewLine & _
           "Press OK to Continue", vbOkOnly, "Moka 5 Compliance Check"
Else
    Dim item, toFix

    For Each item In errors
        toFix = toFix & " - " & item & " is " & errors(item) & vbNewLine
    Next

    Msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
           "The following requires attention:" & vbNewLine & _
           toFix & vbNewLine & _
           "Press OK to Continue", 0, "Moka 5 Compliance Check"
End If