Changing Sound Volume using DOS

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

Changing Sound Volume using DOS

#1 Post by sweener » 20 Sep 2010 18:27

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!

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Changing Sound Volume using DOS

#2 Post by amel27 » 20 Sep 2010 19:09

AFAIK only via 3'd party tools like NirCmd by NirSoft ("changesysvolume" subcommand)

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

Re: Changing Sound Volume using DOS

#3 Post by sweener » 21 Sep 2010 06:18

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Changing Sound Volume using DOS

#4 Post by amel27 » 21 Sep 2010 06:26

sweener wrote:"How do third party tools do it?"

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

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

Re: Changing Sound Volume using DOS

#5 Post by sweener » 21 Sep 2010 11:12

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!

Post Reply