如何使用JScript或VBScript控制Windows系统卷?

如何使用JScript或VBScript控制Windows系统卷?,windows,vbscript,javascript,volume,mute,Windows,Vbscript,Javascript,Volume,Mute,我想通过JScript或VBScript脚本控制Windows系统的音量。有什么想法吗 另外,如果系统卷已静音,是否可以取消静音?在浏览器窗口/网页中-绝对没有办法。即使在技术上可行,浏览器沙盒安全性也会禁止它 从Windows脚本主机(独立的.vbs或.js文件)中—我不知道这是怎么回事。WMI也不提供对此的控制,根据。要使系统音量静音或取消静音,可以使用以下方法模拟静音按键: 至于从脚本更改音量级别,有一种解决方案涉及一些Windows自动化,例如启动系统音量小程序并在其中模拟适当的键盘快捷

我想通过JScript或VBScript脚本控制Windows系统的音量。有什么想法吗


另外,如果系统卷已静音,是否可以取消静音?

在浏览器窗口/网页中-绝对没有办法。即使在技术上可行,浏览器沙盒安全性也会禁止它


从Windows脚本主机(独立的.vbs或.js文件)中—我不知道这是怎么回事。WMI也不提供对此的控制,根据。

要使系统音量静音或取消静音,可以使用以下方法模拟静音按键:

至于从脚本更改音量级别,有一种解决方案涉及一些Windows自动化,例如启动系统音量小程序并在其中模拟适当的键盘快捷键,但我认为这不可靠。因此,我建议您使用一些能够更改音量级别的外部实用程序,并从脚本中调用它。例如,您可以使用免费工具:

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

在Windows7上,我可以通过使用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.
我将它保存到一个名为Mute-Sound.vbs的文件中,并在桌面上创建了一个快捷键来指定快捷键。CTRL+ALT+F12。由于某些原因,键盘快捷键只有在桌面上才能工作,所以我不确定键盘快捷键有多可靠

他使用多媒体键盘静音键的按键。聪明;-)


Misty Manor的答案也适用于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

我所看到的在Windows上操作系统卷级别而无需安装其他软件的最佳方法是通过以下方式之一使用VBScript:

切换静音:(在前面的回答中已经提到)

增加音量级别:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAF))
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAE))
降低音量:

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”运行,它也可以正常工作,因此可以将这些脚本嵌入到可执行文件中并运行它们,而无需将它们保存为单个文件。

我与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]

nircmd非常棒,甚至可以控制应用程序音量和单个混音器控制Hanks Ryan。您在创建()时为我节省了一些时间
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAE))
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]