How do I control my computer master volume by batch file?

Asif webs picture Asif webs · Apr 6, 2014 · Viewed 17.4k times · Source

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));
}

Answer

foxidrive picture foxidrive · Apr 6, 2014

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.