I have written a batch script in an interactive mode, for making some tasks.
Sometimes, These tasks takes a long time to be finished, and then the batch asks if the user wants to go on to the next task, or back to the Batch's Main Menu or... etc
Now, what I want to do, is to add an "Interactive Alarm" command, that sounds a small short beep (Ex: Like the one when we turn on our PCs), to alert the batch user for new questions .
I don't know if this is possible or not, but the most important thing for me, NOT to use a GUI application like WMP or so.. I just want to do this from the Background, even If that beep has to be made from the free speaker, or by using a Third-Party CLI Application (Btw, I've Cygwin installed on my Win7-x64) .
Please note that, I will add that alarm command exactly before the interactive questions, waiting for user's answer to get to the next stage, so I can't just finish the batch, by making a real error beep !
So, would somebody please tell me how to do this ?
Appreciate your help :)
Create a batch file and type inside it: "echo ^G" where ^G is the character representing the beep as mentioned in this page. If it makes double beeps, add "echo off" line at the beginning of the batch file.
Select Control Panel to open it. Click on Hardware and Sound. Under Sound, click on Change system sounds. Now under the Sounds tab, browse to and select Default Beep.
rundll32.exe Kernel32.dll,Beep 750,300
or
rundll32.exe cmdext.dll,MessageBeepStub
or
rundll32 user32.dll,MessageBeep
With rundll functions you''ll no need special symbols like ^G
. With the first method you can also set the frequency and the time you want to beep.
UPDATE
another options are:
powershell "[console]::beep(500,300)"
or using systemSounds.bat
call systemsounds.bat beep
rundll32.exe Kernel32.dll,Beep 750,300
- this does not work well on modern windows systems as rundll32 no longer accepts integer values through command line and this will play the beep with the default values which is too long (and frequency is irritating)
As the capability of beeping depends also on the mainboard and if the mainboard has a system speaker - which more and more becomes a rarity - the systems more and more depend on the normal speakers. So an option is to play sound through them. Here are some options:
Using the speaking capabilities of the SAPI.SpVoice
:
mshta "javascript:code(close((V=(v=new ActiveXObject('SAPI.SpVoice')).GetVoices()).count&&v.Speak('beep')))"
Here this is wrapped in a batch file and the words can be passed as an argument
SAPI.SpVoice
can be used for playing wav
files and you have some coming with the windows installation.You can use this script:
spplayer.bat "C:\Windows\Media\Windows Navigation Start.wav"
Another option - using the windows media player active-x objects to play a sound. On windows XP it was not installed by default but I think for the newer windows versions it is. It also can play mp3
files:
call mediarunner.bat "C:\Windows\Media\Ring03.wav"
And one a little bit obscure - using the <bgsound>
tag from internet explorer (which also can play mp3 files). Here's the script:
call soundplayer.bat "C:\Windows\Media\tada.wav"
And here's a way to use the BEL
character to produce sound with easy to copy-paste code (I've called it a beeper.bat
):
@echo off setlocal ::Define a Linefeed variable (set LF=^ %=-=% ) for /f eol^=^%LF%%LF%^ delims^= %%A in ( 'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x07"' ) do echo(%%A
It's not possible to type the BEL
directly in (for example) notepad.
To get it, type echo ^G>>yourbatch.bat
on the command line (don't type ^
G
, but <Control>-G
, which will be shown as ^G
on the screen). That puts a strange looking character to the end of your file. That's the BEL
character 0x007 ("control-G"). Just copy/move it to any echo
command, you like. Also
set /p "input=^Ggive value: "
is possible (where the ^G
represents that strange char)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With