Question

I have the following batch code. However, this code only turns up my PC volume, but I want to also turn down my volume. How can I achieve this?

@if (@a==@b) @end /*

:: Batch portion

@echo off

cscript /e:jscript "%~f0"

:: JScript portion */

var shl = new ActiveXObject("WScript.Shell");
for (var i = 0; i < 5; i++) {
    shl.SendKeys(String.fromCharCode(0xAF));
}
Was it helpful?

Solution

These are tested and work here - the keycodes are in the Microsoft link in the comment below.

Volume control UP.bat

@if (@a==@b) @end /*

:: batch portion

@ECHO OFF

cscript /e:jscript "%~f0"


:: JScript portion */

var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<5; i++) {
    shl.SendKeys(String.fromCharCode(0xAF));
}

Volume control DOWN.bat

@if (@a==@b) @end /*

:: batch portion

@ECHO OFF

cscript /e:jscript "%~f0"


:: JScript portion */

var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<5; i++) {
    shl.SendKeys(String.fromCharCode(0xAE));
}

Original answer follows:

According to the comment from Kul-Tigin below, the correct code should be AE

shl.SendKeys(String.fromCharCode(0xAF));

You can use a utility to show you the keycodes when you press the up and down volume buttons, assuming you find a utility that returns a keycode for them.

The utility will have to show AF hex or 175 decimal for your up volume key, and then it should show you the correct number for your down volume key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top