回答
静音或取消静音系统卷,则可以使用WshShell.SendKeys
方法模拟静音按键:
var oShell = new ActiveXObject("WScript.Shell");
oShell.SendKeys(Chr(&HAD));
至于从脚本改变音量,还有涉及某些Windows自动化的解决方案,例如启动System Volume小应用程序并在其中模拟适当的键盘快捷键,但我认为它不可靠。因此,我建议您使用一些能够更改音量级别的外部实用程序,并从脚本中调用它。例如,你可以使用免费的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
从浏览器窗口/网页中 - 绝对没有办法。即使技术上可行,浏览器沙箱安全也会禁止它。
从Windows脚本宿主(standalone .vbs或.js文件) - 没有办法,我知道。根据this question,WMI不提供对此的控制权。
在Windows 7上我可以通过控制使用WScript的击键做到这一点。
set oShell = CreateObject("WScript.Shell")
oShell.run"%SystemRoot%\System32\SndVol.exe"
WScript.Sleep 1500
oShell.SendKeys"{TAB} " ' Tab to the mute and press space
oShell.SendKeys"%{F4}" ' ALT F4 to exit the app.
我在一个叫静音,Sound.vbs文件保存它,并在桌面上创建一个快捷方式指定快捷键。 CTRL + ALT + F12。由于某些原因,键盘快捷键只有在桌面上才有效,所以我不确定键盘快捷键的可靠性如何!
http://www.nilpo.com/2008/11/windows-xp/mute-sound-volume-in-wsh/ 他使用多媒体键盘静音键的按键。聪明;-)
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAD))
Misty庄园的答案也适用于Windows Vita。这个,我从字面上来看,就是在某种意义上也是这样。
set oShell = CreateObject("WScript.Shell")
oShell.run"%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
WScript.Sleep 1500 'Waits For The Program To Open
oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It
oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20
oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20
oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20
oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20
oShell.SendKeys"%{F4}" ' ALT F4 To Exit The App.
如果要降低音量,你会做
oShell.SendKeys("{PGDN}") 'It Will Decrease The Volume By 20
这不提供问题的答案。要批评或要求作者澄清,在他们的帖子下留下评论 - 你总是可以评论你自己的帖子,一旦你有足够的[声誉](http://stackoverflow.com/help/whats-reputation),你会能够[评论任何帖子](http://stackoverflow.com/help/privileges/comment)。 – 2014-05-04 16:48:28
那里,我编辑它。 – Jonco98 2014-05-04 16:54:16
我可以看到用于操作在Windows系统的音量,而无需安装额外的软件,最好的办法是使用VBScript中下列方法之一:
切换静音:(已在前面的回答中提到)
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAD))
提高音量:
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAF))
降低音量:
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAE))
这应该最先进的Windows机器上运行。我已经在Windows 7和8.1上测试了它,即使在LC中使用“do as”运行时也可以正常工作,因此可以将这些脚本嵌入到可执行文件中并运行它们,而无需将它们另存为单个文件。
谢谢瑞恩。你为我节省了一些时间来创建([我在超级用户上发布的指南,如何使用JavaScript进行此操作](http://superuser.com/a/1130667/401839)) – TOOGAM 2016-10-02 15:22:58
我用nircmd.exe以及vbscript来控制系统音量。
Set objShell = CreateObject("WScript.Shell")
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
WScript.Quit
End If
objShell.Run("nircmd.exe setvolume 0 0 0")
'Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Popup "Success", "5", "MuteSpeaker"
' to successfully run this vbscript during log-off, nircmd.exe during should be present in "C:\Windows\System32"
' [cscript //X scriptfile.vbs MyArg1 MyArg2]
- 1. 使用JScript或VBScript自定义动作
- 2. 如何从JScript或Testcomplete调用Windows API?
- 3. 如何查找系统卷?
- 4. JScript/VBScript错误
- 5. 如何使日志系统,龙卷风
- 6. 本地版本控制系统(Windows)
- 7. 如何使用Mongodb直接编写或使用Subversion等版本控制系统?
- 8. 简单的版本控制系统或版本控制文件系统或版本控制数据库
- 9. VBScript/JScript网络:连接UDP或TCP
- 10. 如何使用Java程序将文件从Linux系统复制到Windows系统?
- 11. 如何测试“Microsoft Windows 7 Home Premium”是否是使用VBScript的操作系统?
- 12. Windows控制台子系统如何工作?
- 13. 我可以使用JavaScript(JScript)或VBScript的.NET Framework吗?
- 14. 是否可以使用VBScript或JScript实例化SharePoint对象?
- 15. 源控制系统
- 16. 如何从JScript执行VBScript代码?
- 17. 如何使用QProcess中或系统
- 18. Windows中的JScript或JQuery
- 19. 如何在可可中使用系统调用卷曲
- 20. 日历控制使用系统Windows窗体日历C#Windows窗体
- 21. 如何判断一个Windows PE文件是编程控制台子系统还是Windows子系统?
- 22. 如何使用CVS配置巡航控制系统
- 23. 如何使用修订控制系统,一般
- 24. 如何使用Parse功能控制日历系统?
- 25. 如何在新控制台上使用“rvm系统”?
- 26. 如何使用巡航控制系统的配置文件
- 27. 访问网站 - JScript,VBScript?
- 28. 如何通过控制台应用程序在Windows中延迟系统关机?
- 29. 系统托盘应用程序来控制Windows服务
- 30. 版本控制系统c#
即使对于Windows 7(32位),此功能也完美无瑕!但是,我有一个更正,因为“mutesysvolume 0”是取消静音,“mutesysvolume 1”是静音。 – 2010-02-07 10:07:27
哦,对。修正了。 – Helen 2010-02-07 15:10:21
nircmd真棒,甚至可以控制应用程序音量和个别调音台控件 – akostadinov 2014-01-12 19:25:13