17
3
What I need
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:
- anything that comes with Windows 7 Home Premium
- anything that comes with Cygwin
- Perl
- Python
- Ruby
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.
What I don't need
- There are a few similar questions that mostly deal with setting the volume. Most of all, I need to get the volume, not set.
- There is
nircmdc
, which supports setting volume, but not getting. - There is a key[1] in my registry that has values that change predictably when I adjust the volume via the GUI mixer, but I'd guess reading from that key is prone to breakage on hardware changes or system upgrades. Unless I can rely on the solution being reasonably future-proof, I can't use it.
- There are
AutoHotKey
andWSH
solutions for setting the volume on the Web, but a) they too are only good for setting and, worse, b) they useSendKeys
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
Semms like WMI is not an option :(
– Der Hochstapler – 2012-02-28T14:59:53.533Possibly relevant: http://superuser.com/questions/284527/where-are-the-vista-win7-volume-mixer-settings-stored
– Der Hochstapler – 2012-02-28T15:01:28.600Do you need me to expand my answer? I wasn't sure of you needed more, since you seem to have experience with programming. I can provide an example on how you can use AutoHotkey to easily achieve your goal. – iglvzx – 2012-03-01T22:37:52.220
I think it's a very good suggestion, thanks again, but AHK bit me once and I'm shy ever since. I probably wouldn't use it even if it was a fully fledged-out solution. Nothing keeping you from expanding on it for future readers/more upvotes though. :) – peth – 2012-03-01T23:12:34.773
1
(as a note that reg. doesn't even seem to exist on my box, so...it may be unstable indeed). See also my c++ answer here: http://stackoverflow.com/a/21056089/32453
– rogerdpack – 2014-01-10T23:05:01.493