我想通过JAVAScript或VBScript脚本控制Windows系统的音量。有任何想法吗?
另外,如果系统音量已静音,是否可以取消静音?

最佳答案

要使系统音量静音或取消静音,可以使用 WshShell.SendKeys 方法模拟“静音”按键:

var oShell = new ActiveXObject("WScript.Shell");
oShell.SendKeys(Chr(&HAD));

至于从脚本更改音量级别,有一个解决方案涉及一些Windows自动化,例如启动“系统音量”小程序并在其中模拟相应的键盘快捷键,但我认为它不可靠。因此,我建议您使用一些能够更改音量级别的外部实用程序,然后从脚本中调用它。例如,您可以使用免费的NirCmd工具:
var oShell = new ActiveXObject("WScript.Shell");

// Increase the system volume by 20000 units (out of 65535)
oShell.Run("nircmd.exe changesysvolume 20000");

// Decrease the system volume by 5000 units
oShell.Run("nircmd.exe changesysvolume -5000");

NirCmd也可以使系统音量静音或取消静音:
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run("nircmd.exe mutesysvolume 0");  // unmute
oShell.Run("nircmd.exe mutesysvolume 1");  // mute
oShell.Run("nircmd.exe mutesysvolume 2");  // switch between mute and unmute

09-12 22:37