Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 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?


  1. HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E96C-E325-11CE-BFC1-08002BE10318}\0000\MixerSettings\eLineOutTopo\PrimaryNode000
share|improve this question
    
Semms like WMI is not an option :( –  Oliver Salzburg Feb 28 '12 at 14:59
    
Possibly relevant: superuser.com/questions/284527/… –  Oliver Salzburg Feb 28 '12 at 15:01
    
Do 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 Mar 1 '12 at 22:37
    
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. :) –  user112553 Mar 1 '12 at 23:12
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: stackoverflow.com/a/21056089/32453 –  rogerdpack Jan 10 at 23:05
add comment

2 Answers

This question was asked and answered on StackOverflow: http://stackoverflow.com/questions/4640106/how-to-get-current-volume-of-system-sound-device-in-windows-7

The answer: http://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.

share|improve this answer
    
Thanks for the pointer! Will I have to code this myself or do you maybe know of a little tool that sprang from the question/answer? I haven't touched C# before: if I have to code it myself, is there a compiler freely available? –  user112553 Feb 28 '12 at 15:05
    
At worst you'll need to download Visual Studio C# Express, which is free: microsoft.com/visualstudio/en-us/products/2010-editions/… –  music2myear Feb 28 '12 at 15:20
    
I only found this particular answer while searching for a solution to your question. I have not pursued further research to see if there's a compiled binary already publicly available. –  music2myear Feb 28 '12 at 15:20
    
This google search appears to have some promise: google.com/search?q=get+current+volume+by+command+line+windows –  music2myear Feb 28 '12 at 15:22
1  
That one appears to be C# oriented. If you're looking for a C++'ish option, see stackoverflow.com/a/21056089/32453 –  rogerdpack Jan 10 at 23:04
show 1 more comment

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.

share|improve this answer
    
here's one that does it: gist.github.com/rdp/8363141 (though a straight console app for it may be simpler/easier, see other comments here) –  rogerdpack Jan 13 at 17:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.