How to control Windows system volume using JScript or VBScript? How to control Windows system volume using JScript or VBScript? windows windows

How to control Windows system volume using JScript or VBScript?


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)

Set WshShell = CreateObject("WScript.Shell")WshShell.SendKeys(chr(&hAD))

Increase volume level:

Set WshShell = CreateObject("WScript.Shell")WshShell.SendKeys(chr(&hAF))

Decrease volume level:

Set WshShell = CreateObject("WScript.Shell")WshShell.SendKeys(chr(&hAE))

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.


To mute or unmute the system volume, you can simulate the Mute key press using the WshShell.SendKeys method:

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

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:

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 unitsoShell.Run("nircmd.exe changesysvolume -5000");

NirCmd can also mute or unmute the system volume:

var oShell = new ActiveXObject("WScript.Shell");oShell.Run("nircmd.exe mutesysvolume 0");  // unmuteoShell.Run("nircmd.exe mutesysvolume 1");  // muteoShell.Run("nircmd.exe mutesysvolume 2");  // switch between mute and unmute


On Windows 7 I could do this by controlling the keystrokes using WScript.

set oShell = CreateObject("WScript.Shell") oShell.run"%SystemRoot%\System32\SndVol.exe" WScript.Sleep 1500 oShell.SendKeys"{TAB} " ' Tab to the mute and press spaceoShell.SendKeys"%{F4}"  ' ALT F4 to exit the app.

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!