Popup Window with 3 buttons not working

December 5, 2018 at 13:16:12
Specs: Windows 10
I'm trying to create a window with 3 buttons using vb script and batch.
I want to enable a different custom action depending on what button is clicked.
All 3 buttons result in the same action.
What am I doing wrong?
Code below

@ECHO OFF
echo WScript.Quit MsgBox("Do you want to run the program now?", vbYesNoCancel) > #.vbs
cscript //nologo #.vbs
@echo %errorlevel%
del #.vbs
If ERRORLEVEL 0 goto yes
If ERRORLEVEL 1 goto no
If ERRORLEVEL 2 goto cancel

:yes
echo msgbox "yes clicked!" ,64, "Information" > %tmp%\yes.vbs
cscript /nologo %tmp%\yes.vbs
del %tmp%\yes.vbs
del #.vbs
Exit

:no
echo msgbox "no clicked!" ,64, "Information" > %tmp%\no.vbs
cscript /nologo %tmp%\no.vbs
del %tmp%\no.vbs
del #.vbs
Exit

:cancel
echo msgbox "cancel clicked!" ,64, "Information" > %tmp%\cncl.vbs
cscript /nologo %tmp%\cncl.vbs
del %tmp%\cncl.vbs
del #.vbs
pause

message edited by tim5211


See More: Popup Window with 3 buttons not working

Reply ↓  Report •

#1
December 6, 2018 at 03:44:12
try replacing:

If ERRORLEVEL 0 goto yes
If ERRORLEVEL 1 goto no
If ERRORLEVEL 2 goto cancel

with:

if %errorlevel%==0 goto yes
if %errorlevel%==1 goto no
if %errorlevel%==2 goto cancel

could be that batch only accepts %1 variables, i can check for you. but try the above first.

i5-6600K[delid]@4.8GHz/4.4GHz@1.424v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1415Mhz core@1.2v/1920MHz


Reply ↓  Report •

#2
December 7, 2018 at 20:47:11
Hi hidde663.
Thanks for your reply and input!

I tested the batch file again with what you provided, but I'm afraid the result is still the same.
All 3 buttons trigger a YES response


Reply ↓  Report •

#3
December 8, 2018 at 21:54:25
This was all I needed to modify from your code, and then it seemed to work:

If %ERRORLEVEL%==6 goto yes
If %ERRORLEVEL%==7 goto no
If %ERRORLEVEL%==2 goto cancel

The syntax of "IF ERRORLEVEL xx" can be confusing, because this rendition means "if errorlevel >= xx then...", NOT "if errorlevel = xx". So you have to be very careful how you arrange your code using this syntax. Hide66 has it right to just use %errorlevel% syntax. It is much less prone to error and misinterpretation.

message edited by nbrane


Reply ↓  Report •

Related Solutions

#4
December 8, 2018 at 23:23:30
Hi again.

I tried your modified code in my script, but I still keep getting YES for every option.
I can't get it to work


Reply ↓  Report •

#5
December 8, 2018 at 23:34:12
I also changed the variables slightly based on another previous script I made.
Same Result though.


if %ERRORLEVEL% EQU 6 goto yes
if %ERRORLEVEL% EQU 7 goto no
if %ERRORLEVEL% EQU 2 goto cancel


Reply ↓  Report •

#6
December 9, 2018 at 03:14:18
Also found this list of commands

https://www.vbsedit.com/html/ae073d...


Reply ↓  Report •

#7
December 9, 2018 at 08:20:35
fixed!

@ECHO OFF
echo WScript.Quit MsgBox("Do you want to run the program now?", vbYesNoCancel) > #.vbs
cscript //nologo #.vbs
If "%ERRORLEVEL%"=="6" goto yes
If "%ERRORLEVEL%"=="7" goto no
If "%ERRORLEVEL%"=="2" goto cancel
::errorlevel gets reset by the del command 1 line below.
del #.vbs
echo failure...
exit/b
:yes
echo msgbox "yes clicked!" ,64, "Information" > %tmp%\yes.vbs
cscript /nologo %tmp%\yes.vbs
del %tmp%\yes.vbs
del #.vbs
Exit/b
:no
echo msgbox "no clicked!" ,64, "Information" > %tmp%\no.vbs
cscript /nologo %tmp%\no.vbs
del %tmp%\no.vbs
del #.vbs
Exit/b
:cancel
echo msgbox "cancel clicked!" ,64, "Information" > %tmp%\cncl.vbs
cscript /nologo %tmp%\cncl.vbs
del %tmp%\cncl.vbs
del #.vbs
pause
exit/b

i5-6600K[delid]@4.8GHz/4.4GHz@1.424v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1415Mhz core@1.2v/1920MHz

message edited by hidde663


Reply ↓  Report •

#8
December 9, 2018 at 16:00:34
I went back and reviewed my code, and sure enough, I had "rem'd" out the 'del #.vbs' there at the top, leaving it to be done in the three branches. I should have posted my whole code, but I forgot I'd made that change. Oh well, looks like things are swimming now.

Reply ↓  Report •

Ask Question