如何使用JScript或VBScript控制Windows系统音量?
我想通过 JScript 或 VBScript 脚本控制 Windows 系统的音量。有什么想法吗?
另外,如果系统音量已静音,我可以取消静音吗?
I want to control the volume of my Windows system from a JScript or VBScript script. Any ideas?
Also, can I unmute the system volume if it is muted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为在 Windows 上操作系统音量级别而无需安装其他软件的最佳方法是通过以下方式之一使用 VBScript:
切换静音:(在之前的答案中已提到)
增加音量级别:
降低音量级别:
这应该适用于大多数现代 Windows 机器。我已经在 Windows 7 和 8.1 上对此进行了测试,即使在 LC 中使用“do as”运行时它也能正常工作,因此可以将这些脚本嵌入到可执行文件中并运行它们,而无需将它们保存为单独的文件。
The best way I can see for manipulating the system volume level on Windows without the need for installing additional software is to use VBScript in one of the following ways:
Toggle muted: (already mentioned in a previous answer)
Increase volume level:
Decrease volume level:
This should work for most modern Windows machines. I've tested this on Windows 7 and 8.1 and it works fine even when run with "do as" in LC, so it is possible to embed these scripts within an executable and run them without the need of saving them as individual files.
要使系统音量静音或取消静音,您可以使用 < code>WshShell.SendKeys 方法:
至于从脚本更改音量级别,有一个涉及一些 Windows 自动化的解决方案,例如启动系统音量小程序并在其中模拟适当的键盘快捷键,但我认为这不可靠。因此,我建议您使用一些能够更改音量级别的外部实用程序,并从脚本中调用它。例如,您可以使用免费的 NirCmd 工具:
NirCmd 还可以使系统音量:
To mute or unmute the system volume, you can simulate the Mute key press using the
WshShell.SendKeys
method:As for changing the volume level from a script, there's a solution that involves some Windows automation, such as launching the System Volume applet and simulating the appropriate keyboard shortcuts in it, but I don't think it's reliable. Therefore I recommend that you use some external utility capable of changing the volume level, and call it from your script. For example, you could use the free NirCmd tool:
NirCmd can also mute or unmute the system volume:
在 Windows 7 上,我可以通过使用 WScript 控制击键来做到这一点。
我将其保存到名为 Mute-Sound.vbs 的文件中,并在桌面上创建了一个快捷方式来分配快捷键。 CTRL+ALT+F12。由于某种原因,键盘快捷键只有在桌面上才有效,所以我不确定键盘快捷键有多可靠!
On Windows 7 I could do this by controlling the keystrokes using WScript.
I saved it in to a file called Mute-Sound.vbs and created a shortcut on the desktop to assign a shortcut key. CTRL+ALT+F12. For some reason the keyboard shortcuts only work if they are on the desktop so I am not sure how reliable keyboard shortcuts are!
Misty Manor 的答案也适用于 Windows Vita。这,我刚刚做的,在某种意义上也是一样的。
如果你想降低音量,你可以这样做
Misty Manor's Answer Works on Windows Vita as well. This, i literally just made, does the same in a sense.
If you want to decrease the volume you would do
http://www.nilpo.com/ 2008/11/windows-xp/静音音量-in-wsh/
他使用多媒体键盘静音键进行击键。聪明的 ;-)
http://www.nilpo.com/2008/11/windows-xp/mute-sound-volume-in-wsh/
He uses a keystroke of a Multimedia Keyboard mute key. Clever ;-)
从浏览器窗口/网页内 - 绝对不可能。即使技术上可行,浏览器沙箱安全也会禁止它。
从 Windows 脚本宿主(独立的 .vbs 或 .js 文件)内部 - 据我所知,这是不可能的。根据这个问题,WMI 也不提供对此的控制。
From within a browser window/web page - definitely no way at all. Browser sandbox security would prohibit it even if it were technically possible.
From within Windows Script Host (standalone .vbs or .js file) - no way that I am aware of. WMI does not provide control over this either, according to this question.
我使用 nircmd.exe 以及 vbscript 来控制系统音量。
I used nircmd.exe along with vbscript to control system volume.