Destroyer
Destroyer

Reputation: 679

Stop Batch File from Beeping

For some reason my batch script beeps when pressing Space at a PAUSE event.

I currently have both:

start /wait %comspec% /Q /C "net stop beep" >nul 2>&1
start /wait %comspec% /Q /C "sc stop beep" >nul 2>&1

...at the start of my script, which has successfully disabled the system beep, but now it has been replaced by a Windows "themed" beep.

Also this happens when I get to a CHOICE event and the user presses Space.

Any ideas on how to make a batch script completely silent, even during input "errors"?

Thanks, D

Upvotes: 3

Views: 3434

Answers (2)

rojo
rojo

Reputation: 24466

Try replacing your choice commands with something like this.

set /p choice="Please enter a choice: "

It'll require the user to hit enter but at least it won't beep.

If you really want to do it the hard way and turn off the default sound, I think you'll find it either in HKCU\AppEvents\Schemes\Apps\.Default\SystemAsterisk\.Current\(Default) or in HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault\.Current\(Default).

Here's a brief proof of concept.

@echo off
setlocal

:: stop bleeping service
start /wait %comspec% /Q /C "sc stop beep" >nul 2>&1

:: store current event setting for Asterisk
set loc=HKCU\AppEvents\Schemes\Apps\.Default\SystemAsterisk\.Current
for /f "tokens=3*" %%I in ('reg query %loc%') do (
    set asterisk=%%I %%J
)

:: choice with service stopped and Windows Asterisk sound event still active
choice

:: set Windows Asterisk event sound to ""
reg add "%loc%" /v "" /t REG_SZ /d "" /f >NUL

:: choice with asterisk set to ""
choice

:: restore the sound
reg add "%loc%" /v "" /t REG_SZ /d "%asterisk%" /f >NUL

If that doesn't work, try replacing SystemAsterisk with AppGPFault. To be honest, I'm unable to recreate your symptom. I hear silence after stopping the beep service. So I'm not entirely sure which event is getting triggered when a user hits the space bar and the beep service is stopped.

Upvotes: 1

James K
James K

Reputation: 4055

You could always record a moment of silence, then use that to replace one of the Windows themed beeps.

I recommend that you post a little more of your code so we can see what is causing the beeps, because PAUSE should not do that.

Upvotes: 0

Related Questions