I'm looking for a tool or a script that allows me to access the Windows volume levels from the command line. Ideally it would allow me to get and set all volumes including application levels, but I'd settle for only getting, and only the master level. I don't mind if it uses PowerShell
, WMI
, JavaScript
, .Net
, Voodoo, or butterflies. Any solution that will just give me a number that I can further process to fit a range from 0% to 100% will do.
Put another way, the prompt parts are the black box that I need filled:
C:\> getvol master
50
or even
C:\> wmic <alias> where "device='master' and name='volume'" get name,value
Name Value
Volume 0xDEADBEEF
I don't mind if I have to spend some time to wrap it or even write something myself if the tools to do so are freely available. In the latter case, I'd need some pointers/proof-of-concept for the core, but I can manage the cruft on my own. Also I'd like to avoid installing new development frameworks just for this purpose (note that both music2myear's and iglvzx's answers were given before I introduced these requirements).
As "platforms", I have available:
Generally, open-source solutions are greatly preferred. Closed-source tools are ok as long as they're freeware and the source can be trusted. Commercial solutions are no-go.
nircmdc
, which supports setting volume, but not getting.AutoHotKey
and WSH
solutions for setting the volume on the Web, but a) they too are only good for setting and, worse, b) they use SendKeys
or automated mouse movement to control the GUI. Automating the GUI is not an option.The ##windows
channel on freenode is unhelpful as ever, Google overflows with hacks and half-baked workarounds, and I can't tell a WinAPI call from a Wiccan incantation.
Does anyone know of a way?
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E96C-E325-11CE-BFC1-08002BE10318}\0000\MixerSettings\eLineOutTopo\PrimaryNode000
This question was asked and answered on StackOverflow: https://stackoverflow.com/questions/4640106/how-to-get-current-volume-of-system-sound-device-in-windows-7
The answer: https://stackoverflow.com/a/4640225/704977
You're looking for the EndpointVolume API. This is part of the new audio APIs that were released in Windows Vista, and it can be used to get or set the master volume.
... There's a complete managed wrapper library available on CodeProject: Vista Core Audio API Master Volume Control.
I know you said you did not want an AutoHotkey solution, but I believe the AutoHotkey API has what you are looking for:
You do not need to create GUIs or use hotkeys with AutoHotkey. You can write powerful command line utilities by compiling an .ahk
script. That being said, you will want to look at the FileAppend command for working with stdout
.
The master volume is stored in the registry location:
...\#eSpeakerTopo\Properties\{7fb7b48f-531d-44a2-bcb3-5ad5a134b3dc}
For example, this REG file sets the master volume to 100%.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\DeviceClasses\{6994ad04-93ef-11d0-a3cc-00a0c9223196}\##?#HDAUDIO#FUNC_01&VEN_8384&DEV_7680&SUBSYS_83847680&REV_1034#4&31e60982&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\#eSpeakerTopo\Properties\{7fb7b48f-531d-44a2-bcb3-5ad5a134b3dc}\20000]
@=hex(ffff1003):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00
The key name may differ. You need to restart for changes to take effect.
You may not be able to edit or open the Properties
or {7fb7b48f-531d-44a2-bcb3-5ad5a134b3dc}
key in regedit
. Although you have the necessary access permissions, you may receive an error like this:
[Window Title]
Error Opening Key
[Content]
{7fb7b48f-531d-44a2-bcb3-5ad5a134b3dc} cannot be opened.
An error is preventing this key from being opened.
[OK]
This is because the key name is too long. You will have to temporarily rename the long key name to one character and then rename it back.
User contributions licensed under CC BY-SA 3.0