Patrick Vest
Patrick Vest

Reputation: 1

Using If Then Else statement with vbs message box

I am attempting to use VBS to determine what answer a user clicks when a dialog box opens. I want to set it up so that when the user clicks "yes", the VBS executes a batch file using an If Then Else Statement. Here is the code I have so far. The message box opens but the .bat does not.

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

The vertical bars signify my comments.

Upvotes: 0

Views: 3494

Answers (1)

Ken White
Ken White

Reputation: 125718

You're assigning the result of msgbox to variable x, but testing some unknown variable returnvalue in your if statement. You should be checking for if x = 6 instead, or 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

Upvotes: 1

Related Questions