HOME
Stephen Knight
03/11/2013 04:27 PM
GUI Yes/No or Message box in batch file

Type:

VBScript, Batch/Command file

Category:

This script demonstrates a way to show a GUI messagebox from a batch file to ask Yes/No question, and return the answer to a batch file, also a plain text box with just an "OK"

Hide details for CodeCode
@echo off
Call :YesNoBox "Are you sure you want to do that?"
if "%YesNo%"=="7" (
Call :MessageBox "You answered NO" "Heading"
exit /b
)

exit /b
:YesNoBox
REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
set heading=%~2
set message=%~1
echo wscript.echo msgbox(WScript.Arguments(0),%MsgType%,WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set YesNo=%%a
exit /b

:MessageBox
set heading=%~2
set message=%~1
echo msgbox WScript.Arguments(0),0,WScript.Arguments(1) >"%temp%\input.vbs"
cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"
exit /b


Hide details for ExplanationExplanation
Hide details for ExamplesExamples


Hide details for AttachmentsAttachments