windows 如何使用批处理文件从内置 pc 扬声器启动系统“哔”声?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27079534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:50:41  来源:igfitidea点击:

How to start a system "beep", from the built-in pc speaker, using a batch file?

windowsbatch-filecygwin

提问by KorkOoO

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 .

现在,我想要做的是添加一个“交互式警报”命令,它会发出一声短促的哔哔声(例如:就像我们打开 PC 时发出的那样),以提醒批处理用户有新问题。

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) .

我不知道这是否可行,但对我来说最重要的是,不要使用像 WMP 之类的 GUI 应用程序。我只想从后台执行此操作,即使必须发出哔声从免费扬声器,或通过使用第三方 CLI 应用程序(顺便说一句,我在我的 Win7-x64 上安装了 Cygwin)。

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 :)

感谢你的帮助 :)

采纳答案by Stephan

It's not possible to type the BELdirectly in (for example) notepad.

无法BEL直接在(例如)记事本中键入。

To get it, type echo ^G>>yourbatch.baton the command line (don't type ^G, but <Control>-G, which will be shown as ^Gon the screen). That puts a strange looking character to the end of your file. That's the BELcharacter 0x007 ("control-G"). Just copy/move it to any echocommand, you like. Also

要获取它,请echo ^G>>yourbatch.bat在命令行上键入(不要键入^G, 但<Control>-G,它将显示^G在屏幕上)。这会在文件末尾放置一个看起来很奇怪的字符。那是BEL字符 0x007(“control-G”)。只需将其复制/移动到echo您喜欢的任何命令即可。还

set /p "input=^Ggive value: "

is possible (where the ^Grepresents that strange char)

是可能的(其中^G代表那个奇怪的字符)

回答by npocmaka

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.

使用 rundll 函数,您将不需要像^G. 使用第一种方法,您还可以设置想要发出哔哔声的频率和时间

You can check also this

你也可以检查这个

回答by cascading-style

@echo off
echo BEEP.BAT by CSS---
echo PRESS ANY KEY TO HEAR A BEEP...
PAUSE>NUL
ECHO 
echo I BEEPED
PAUSE

there is an ASCII control code ^G after the echo. Just copy this code, and save it as ASCII/ANSI using a text editor.

回声后有一个 ASCII 控制代码 ^G。只需复制此代码,然后使用文本编辑器将其保存为 ASCII/ANSI。

回答by RGuggisberg

use ECHO command to echo a CTRL G

使用 ECHO 命令回显 CTRL G

回答by José L. Bello

I think the better solution is echoing a ^Gto a file from the cmd prompt and then type that file from within the script, that way you don't need to include control characteres in the batch file itself:

我认为更好的解决方案是^G从 cmd 提示符将 a回显到文件,然后从脚本中键入该文件,这样您就不需要在批处理文件本身中包含控制字符:

C:\> echo ^G>beep.snd

Now there's an ASCII 007 char in the "beep.snd" file, then from your .bat file all you have to do is type it or copy to the screen:

现在“beep.snd”文件中有一个 ASCII 007 字符,然后从您的 .bat 文件中输入它或复制到屏幕:

type beep.snd

or

或者

copy beep.snd con > nul