Page 1 of 1

Changing Sound Volume using DOS

Posted: 20 Sep 2010 18:27
by sweener
Hey, I did do a search on this in the forum and I saw a SendKey method can be used to mute the volume, but I am interested in controlling the volume via batch, not just muting and unmuting.

Any ideas?

Thanks!

Re: Changing Sound Volume using DOS

Posted: 20 Sep 2010 19:09
by amel27
AFAIK only via 3'd party tools like NirCmd by NirSoft ("changesysvolume" subcommand)

Re: Changing Sound Volume using DOS

Posted: 21 Sep 2010 06:18
by sweener
Hmmm... which only gets me wondering, "How do third party tools do it?". I may give that a shot if nothing else pops up.
Thanks

Re: Changing Sound Volume using DOS

Posted: 21 Sep 2010 06:26
by amel27
sweener wrote:"How do third party tools do it?"

via Win32 API: http://support.microsoft.com/kb/178456

Re: Changing Sound Volume using DOS

Posted: 21 Sep 2010 11:12
by sweener
Well, I did a bit more hunting and it turns out the best way to do this via simple automated means callable from DOS is to write a vbscript. Here's a little something I threw together based on some other stuff I found on ye olde internet:

Code: Select all

'volControlvbs
volUp=WScript.Arguments(0)
sender="{UP "& volUp & "}"

set shl=CreateObject("WScript.Shell")
shl.Run "sndvol32 -T", 2    'the 2 makes the app active and minimized
WScript.Sleep 50
shl.SendKeys "{END}"    'Sets volume to 0
shl.SendKeys sender      'emulates pressing up arrow %volup% amount of times
WScript.Sleep 50
shl.SendKeys "%{F4}"    'Exit app


Mind you there are more efficient ways to do that (WITH statement and other things)

and I would call the script from DOS:

Code: Select all

volControl.vbs 250

which would set the volume about 50%.

Thanks for your reply though. The link you provided started me down a different path until I arrived at this. Thanks amel27!