使用带有vbs消息框的If Then Else语句

时间:2015-01-23 22:52:45

标签: batch-file if-statement vbscript

我正在尝试使用VBS来确定用户在打开对话框时单击的答案。我想设置它,以便当用户单击“是”时,VBS使用If Then Else语句执行批处理文件。这是我到目前为止的代码。消息框打开,但.bat不会。

set shell=createobject("wscript.shell")
x=msgbox("Do you wish for windows Shutdown?" ,4+16, "Confirm")
If returnvalue=6 Then
    shell.run "||||File Adress||||test.bat"
End If

垂直条表示我的评论。

1 个答案:

答案 0 :(得分:1)

您将msgbox的结果分配给变量x,但在returnvalue语句中测试了一些未知变量if。您应该检查if x = 6,或resultvalue = msgbox()

set shell=createobject("wscript.shell")
x = msgbox("Do you wish for windows Shutdown?" , 4 + 16, "Confirm")
If x = 6 Then
    shell.run "||||File Adress||||test.bat"
End If
相关问题