Question

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

Asked by: xenium

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!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-10 at 03:30:06ID24720816
Tags

volume

,

sound

,

VBA

,

DOS

Topics

Microsoft Excel Spreadsheet Software

,

MS DOS

,

Microsoft Windows Operating Systems

Participating Experts
1
Points
250
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VBA
    Is there a way that I could add the PrinterObject to my VBA development in Excel. Instead of using VB6, I would also like to use the PrinterObject in my Excel and Access Visual Basic Programming.
  2. Calculate Volume For Cylinder Using VBA
    Hello All. I am looking for the formula to calculate the volume of a cylinder using VBA. Below are the values in the spreadsheet. I don't know how to calculate it. I have looked at the formula several places on the web. None of the have a VBA version. dblCylVolume = 0....

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BillDLPosted on 2009-09-10 at 06:42:34ID: 25300071

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.

' Clunky slow method to UnMute master volume and maximize slider.
' It has the unfortunate side effect of beeping 5 times as
' it increments the slider using PageUp 5 times to max it.
' Usage: wscript AdjustVol.vbs
 
' Create the program environment 
Set WshShell = WScript.CreateObject("WScript.Shell")
 
' Open Volume Control in single slider view
WshShell.Run "%SystemRoot%\System32\sndvol32.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}"
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:

Select allOpen in new window

 

by: xeniumPosted on 2009-09-10 at 08:52:26ID: 25301427

Thanks

using sendkeys does the job:
 
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys (Chr(173))
 
How can the volume can be set to max using this method? Additionally, chr(173) just switches the mute/unmute. What I need to do is always set it to unmute. Is there a way to check what the current status is and only send chr(173) if it is currently on mute?
 

 

by: BillDLPosted on 2009-09-10 at 13:35:17ID: 25303997

I'm afraid that with me not being a VB or C++ Programmer, I don't really know how to test the status of the Mute box other than to query the registry for the value holding that setting.  Coincidentally I was just looking at what I believed to be the registry keys and values holding the current states of the Volume Control elements in this question:
http://www.experts-exchange.com/Q_24501347.html
See comment ID: 25290174

I will have to look again at the various values to see if one of them reflects the status of the Mute box, but incorporating that into a *.vbs code will be a problem for me because I'm not very advanced with that aspect.

The little script that toggles the mute box on and off is ideal if that's all you needed to do.  The *.vbs code I posted in the Code Snippet field uses the same idea, except it just sends an "Alt + M" keystroke combination to the single volume control (because the M is the underscored character in the Menu) instead of a Key Code 173 - hex AD.  Essentially they do the same thing, but the code I posted is really the only way that my limited knowledge allows me to push the volume slider up to maximum.

I will try to find some other method, but I think it might attract other experts more experienced with coding if you were to click the "Request Attention" button.

 

by: BillDLPosted on 2009-09-11 at 07:19:17ID: 25309750

I know that the following isn't directly what you need, because you seem to be looking for some VBA code to use within Excel, but here are my findings anyway.  Maybe you can translate these findings to your own needs.

In furtherance of detecting the current state of the master volume's

"Mute" checkbox, this is the ONLY relevant change noted in the

registry of my Windows XP SP3 system.

Relevant Registry Key in which changed value was detected:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{69

94AD04-93EF-11D0-A3CC-00A0C9223196}\##?

#PCI#VEN_1102&DEV_0002&SUBSYS_80281102&REV_08#4&122329E2&0&60F0#

{6994ad04-93ef-11d0-a3cc-00a0c9223196}\#WaveCyc\Device

Parameters\Mixer\       0\Controls\       4]

Relevant Value When Unmuted:
"Channel       0"=dword:00000000

Relevant Value When Muted:
"Channel       0"=dword:00000001

Of course, this registry key may well be absolutely unique to my

system and/or my Creative SoundBlaster Live! Value (CT4870) card.

There is an easy enough way to check what value changes in your

registry when checking and unchecking the Mute box, and then we will

know whether each system has a completely different registry key, or

whether that key is the standard for the Windows Volume Control.

While the Mute box is UNchecked, run the following command:

regedit /e "%TEMP%\Unmuted.txt"

"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses"

Without messing around with the computer, immediately pull up the

volume control from the system tray with a single click and Mute it.

Run this command:

regedit /e "%TEMP%\Muted.txt"

"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses"

Download the following free standalone utility to compare the two

registry export files side by side for differences:

http://www.prestosoft.com/edp_examdiff.asp#download

Standalone Program:
http://www.prestosoft.com/download/ed18.zip

There is an installable version too:
http://www.prestosoft.com/download/ed18_setup.exe

Run the following command (or open the program and set the user

options to suit and load the files):

examdiff "%TEMP%\Unmuted.txt" "%TEMP%\Muted.txt" /i /w /b /l /e /t /n

I am pretty sure that it will only show one difference if you didn't

mess around too much in between exporting your two files from Regedit.

The program shows files from the XP registry in the double-spaced

"unicode" style like this when copied out, but it should be enough to

allow you to find the Key containing the changed value and examine it

in Regedit to see if it is the same one that is changed in my

registry.

[ H K E Y _ L O C A L _ M A C H I N E \ S Y S T E M \ C u r r e n t C

o n t r o l S e t \ C o n t r o l \ D e v i c e C l a s s e s \ { 6 9

9 4 A D 0 4 - 9 3 E F - 1 1 D 0 - A 3 C C - 0 0 A 0 C 9 2 2 3 1 9 6 }

\ # # ? # P C I # V E N _ 1 1 0 2 & D E V _ 0 0 0 2 & S U B S Y S _ 8

0 2 8 1 1 0 2 & R E V _ 0 8 # 4 & 1 2 2 3 2 9 E 2 & 0 & 6 0 F 0 # { 6

9 9 4 a d 0 4 - 9 3 e f - 1 1 d 0 - a 3 c c - 0 0 a 0 c 9 2 2 3 1 9 6

} \ # W a v e C y c \ D e v i c e   P a r a m e t e r s \ M i x e r \  

             0 \ C o n t r o l s \               4 ]

If it is the same Key and value name ie. "Channel       0" in the key

I gave earlier, then it would be possible to test this in a *.vbs

script in a similar way to using the REG QUERY command in a batch

file:

reg query "HKLM\System\KeyPath" /v "Channel       0"
 
For a full example of a batch file that would call different *.vbs files dependent on the current "Mute State" value in MY registry, see the attached "Check_Mute_State.cmd" which is attached as a *.txt file because of upload restrictions here.

I am sure that a competent *.vbs coder could condense that check into just a couple of lines and include it with the code to toggle the settings you need, but my basic knowledge of VBS coding would make this risky when messing with the registry.

  • Check-Mute-State.txt
    • 1 KB

    Batch file that tests status of the Mute checkbox under the master volume control ON MY SYSTEM by getting registry value. Save and rename, changing .TXT extension to .CMD

 

by: BillDLPosted on 2009-09-11 at 07:20:53ID: 25309768

Damn, why does this break up long lines into paragraphs.  Here is the broken registry key:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{6994AD04-93EF-11D0-A3CC-00A0C9223196}\##?#PCI#VEN_1102&DEV_0002&SUBSYS_80281102&REV_08#4&122329E2&0&60F0#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\#WaveCyc\Device Parameters\Mixer\       0\Controls\       4]

                                              
1:

Select allOpen in new window

 

by: BillDLPosted on 2009-09-11 at 07:23:45ID: 25309794

Sorry about the double-spaced lines in my comment.  Windows Notepad in XP has a bad habit of messing with the word wrapping.  I usually turn off word wrap after making up my notes, save the file, copy and paste it here, then turn on word wrap again and save it for my own later uses.

 

by: xeniumPosted on 2009-09-11 at 07:57:49ID: 25310175

Thanks a lot, i've passed this onto a colleague and will feedback any news.

Meanwhile, anyone with any quicker/ neater solutions please fire away...

 

by: xeniumPosted on 2009-09-14 at 07:36:38ID: 25325919

My colleague played around a bit with the sendkeys method and found out that sending "-" when the focus is on the mute box always unmutes the volume. So no need to check the registry value. Final code below

Thanks a lot for your valuable help!


#################################################################
Set WshShell = CreateObject("WScript.Shell")
 
'open volume control
 
WshShell.Run "%SystemRoot%\System32\sndvol32.exe /t"
Sleep 200
 
'make active
WshShell.AppActivate ("Volume")
 
'mute (to avoid the beep)
WshShell.SendKeys "%{M}"
WshShell.SendKeys "{+}"
Sleep 200
 
'switch back to volume control
WshShell.SendKeys "{TAB}"
Sleep 200
 
'increase volume to max
 
For i = 1 To 5
    WshShell.SendKeys "{PGUP}"
Next i
Sleep 200
 
'unmute
WshShell.SendKeys "%{M}"
WshShell.SendKeys "{-}"
Sleep 200
 
'close
WshShell.SendKeys "%{F4}"
#################################################################

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:

Select allOpen in new window

 

by: BillDLPosted on 2009-09-14 at 07:49:34ID: 25326055

Thank you xenium.
That was a pretty good discovery about the Minus keystroke always removing the check from the Mute box, and I like the idea of first muting the sound before bumping up the volume slider in 5 steps that would otherwise have beeped at each increment.  Hope you don't mind if  copy the revised code for future use ;-)
Bill

 

by: xeniumPosted on 2009-09-14 at 08:07:25ID: 25326211

Sure, that's what its here for :-) Thanks again.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...