If you want to do everything in a batch file (as asked), I use this technique.
You can read data from within a batch file (and use it by the same batch file) by using the "for /f" command.
For example, here we'll just read the message text at the bottom of the batch file and echo only that in the command window:
@echo off
@for /f "tokens=1,* eol=@ delims= " %%i in (%~0) do @echo %%j
@pause
@rem YOUR MESSAGE HERE:
rem Now is the winter of our discontent
rem Made glorious summer by this sun of York;
rem And all the clouds that lour'd upon our house
rem In the deep bosom of the ocean buried.
The line:
@for /f "tokens=1,* eol=@ delims= " %%i in (%~0) do @echo %%j
is doing the heavy lifting by playing around with the end-of-line character (@) and using the spaces after the bare "rem " lines as the delimeter. I call it "DUYOA.bat", or "Dissappearing Up Your Own...".
Now, we can extend the same principle so that the batch file creates a VBS script, which in turn reads the batch file to create a slave batch file.
The slave batch file is derived from the top of the original batch file wherever "@rem " is the prefix.
Still with me? Don't worry, we're nearly there...
The VBS script is then started by the original batch file, and it runs the slave batch file in the background:
@echo off
rem ' ###########################################
rem ' THIS BATCH FILE READS ITSELF, AND CREATES A
rem ' VBS SCRIPT TO RUN ITSELF IN THE BACKGROUND
rem ' ###########################################
rem ' NOTE: Prefix your original batch commands with "@rem ":
@rem rem Log the starting of the batch file
@rem echo %date% %time% - %random% Started >> %USERPROFILE%\Desktop\Log.txt
@rem D:\ffmpeg\ffplay -autoexit -nodisp "D:\mp3\Incoming.mp3"
@rem D:\ffmpeg\ffplay -autoexit -nodisp "D:\mp3\Incorrect.mp3"
@rem D:\ffmpeg\ffplay -autoexit -nodisp "D:\mp3\Boing.mp3"
@rem rem Don't play the tada sound
@rem rem D:\ffmpeg\ffplay -autoexit -nodisp "C:\Windows\Media\tada.wav"
@rem rem Log the completion of the batch file
@rem echo %date% %time% - %random% Completed >> %USERPROFILE%\Desktop\Log.txt
rem ' ##########################################################
rem ' THE REST OF THIS SCRIPT STAYS THE SAME, EVEN IF THIS BATCH
rem ' FILENAME CHANGES. IT AND CAN BE PASTED INTO ANY BATCH FILE
rem ' WHOSE COMMANDS ARE PREFIXED WITH "@rem "
rem ' ##########################################################
rem ' Any line prefixed with "@" is actioned by this master batch file:
rem ' -----------------------------------------------------------------
@set random=%temp%\%~n0%~x0-%random%.vbs
@echo MasterBatchFileName = "%~n0%~x0" > %random%
@for /f "tokens=1,* eol=@ delims= " %%i in (%~0) do @echo %%j >> %random%
@start %random%
rem ' Any line prefixed with "rem " will be written to the VBS script:
rem ' ----------------------------------------------------------------
rem On error resume next
rem Set fso = CreateObject("Scripting.fileSystemObject")
rem SlaveBatchFileName = fso.GetSpecialFolder(2) & "\" & fso.GetTempName & ".bat"
rem Set aFile = fso.CreateTextFile(SlaveBatchFileName, TRUE)
rem Const OPEN_FILE_FOR_READING = 1
rem Set objInputFile = fso.OpenTextFile(MasterBatchFileName, 1)
rem inputData = Split(objInputFile.ReadAll, vbNewline)
rem For each strData In inputData
rem if left(strData,5)="@rem " then
rem aFile.WriteLine(replace(strData,"@rem ",""))
rem end if
rem Next
rem aFile.Close
rem objInputFile.Close
rem CreateObject("Wscript.Shell").Run SlaveBatchFileName, 0, True
rem Set aFile = fso.GetFile(SlaveBatchFileName)
rem aFile.Delete
rem Set aFile = fso.GetFile(WScript.ScriptFullName)
rem aFile.Delete
If trying to understand it is giving you a headache, just use the bottom half from:
rem ' THE REST OF THIS SCRIPT STAYS THE SAME...
downwards as a subroutine to paste into your batch files, and just prefix all the original commands with "@rem ".
I shove all the child files in the temp directory, and the VBS script deletes them (and itself) on exit.
You can ditch the logging and all the comments to boil it down, and/or go the other way and add a 3 second pop-up right at the bottom of the file as the very last line:
rem wscript.CreateObject("wscript.Shell").Popup MasterBatchFileName & " completed!",3,MasterBatchFileName,4096+64
Now, I know this doesn't cure the command window flash, but it does run the batch file in the background, and you don't need a separate VBS script lying around as per other answers.