Problem : How to unmute windows sound master volume and then increase the volume to max, using VBA

Problem : How to unmute windows sound master volume and then increase the volume to max, using VBA

hi,

is there a way to programmatically control the sound volume in Windows? Ideally in VBA directly, but perhaps via a shell command if this is easy in DOS. Need command to unmute windows sound master volume and then increase the volume to max.

Thanks!


 

Solution: How to unmute windows sound master volume and then increase the volume to max, using VBA

From the following page giving an example full Visual Basic project demonstrating how to manipulate volume control settings:
http://support.microsoft.com/kb/178456
the author of the following page has created a self-registering *.DLL (ActiveX Control) that allows you to call it using a *.vbs script:
http://www.vinsvision.com/Default.aspx?tabid=66&EntryID=12
http://www.vinsvision.com/Downloads/tabid/57/Default.aspx
It was written as a method for setting volume level at logon via a script, but you may be able find it interesting nevertheless.

There are other methods that use 3rd-party programs to which are assigned, or to which you can assign, keyboard shortcuts, or which you can call from the command line, eg:
http://pcworld.about.com/magazine/2001p148id68776.htm
http://www.grc.com/wizmo/wizmo.htm
http://www.nirsoft.net/utils/nircmd.html

Further to the above, you can use a simple *.vbs code that sends the same key code as multimedia keyboards use to toggle the master volume’s Mute check-box on and off without displaying the volume control:

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.SendKeys(chr(173))

or

Set WshShell = CreateObject(“WScript.Shell”)
WshShell.SendKeys(chr(&hAD))

As a matter of interest, the volume control in Windows XP (and I assume upwards) has a few command line switches:

sndvol32 /t – shows single master volume slider like System Tray
sndvol32 /r – open full mixer in “record” view
sndvol32 /p – open full mixer in “playback” view
sndvol32 /s open full mixer in playback mode – SMALL
While open Ctrl + S toggles between small and normal (wide) view.

There would be a few ways of unmuting and max’ing your master volume using basic *.vbs, but they are very clunky and if focus of the object is lost by clicking around or pressing keyboard keys while the VB Script is running, the SendKeys function can send the keystrokes to another application window.  To mitigate the risk, the *.vbs code in the Code Snippet tries to maintain focus on the volume control while it simulates keystrokes.  There may be better ways, but I’m not a programmer.  I know the script isn’t VBA, but nobody else has so far commented so you may as well see one method.

I think something like this would be better dealt with using API calls from an ActiveX Control.  There may be some shell commands available for use, but I’m not sure.

Set WshShell = WScript.CreateObject(“WScript.Shell”)

‘ Open Volume Control in single slider view

WshShell.Run “%SystemRoot%System32sndvol32.exe /t”

‘ Give it 500 milliseconds to load

WScript.Sleep 500

‘ make sure Volume stays on top so keystrokes are sent to it.

WshShell.AppActivate(“Volume”)

‘ Send Page Up keystroke 5 times to slider control

For X = 1 To 5

WshShell.SendKeys “{PGUP}”

WshShell.AppActivate(“Volume”)

Next

‘ Give it 500 milliseconds to finish off

WScript.Sleep 500

‘ Send Alt + M to it to check or uncheck Mute box

WshShell.SendKeys “%{M}”

‘ Give it 500 milliseconds to work

WScript.Sleep 500

‘ make sure Volume is still active

WshShell.AppActivate(“Volume”)

‘ Close it using Alt + F4

WshShell.SendKeys “%{F4}”