Batch File Message Boxes

6 Oct

A quick and dirty script to copy some data from a specific folder on a machine to a USB drive. (I have a longer term plan in mind for this, but my C# skills will need a little brushing up before I get that going).

@echo off
Call :YesNoBox "Do you wish to copy all data to the USB drive?","My Data Copy"
if "%YesNo%"=="6" (
xcopy C:\Data\* .\Data /y
Call :MessageBox "Data Copy Complete","My Data Copy"
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

References: