Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  129] [ 4]  / answers: 1 / hits: 47776  / 15 Years ago, sun, february 7, 2010, 12:00:00

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?


More From » windows

 Answers
4

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 units
oShell.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); // unmute
oShell.Run(nircmd.exe mutesysvolume 1); // mute
oShell.Run(nircmd.exe mutesysvolume 2); // switch between mute and unmute

[#97643] Wednesday, February 3, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;