How to set sound volume programmatically

Hi all,

From time to time I like to post about other issues which are not related to crypto stuff, but I consider useful because of the number of request I get on them. And this is one common question I've seen: how do I set sound volume programmatically on Windows?

On Windows XP we can manipulate audio settings with Wave API or Dsound API (Direct Sound). The following function may help here: waveOutSetVolume. Here is the rest of the API: Waveform Functions. And here we can find a .NET sample which mixes .NET classes and that API: Using P/Invoke to Call Unmanaged APIs from Your Managed Classes. Another sample, this time from a third-party: Mute volume in vb.net program.

On Windows Vista and later that API is no longer available. We may use MMDevice API and EndpointVolume API instead. Here you can see some samples: How do I change the master volume in Windows Vista & Vista Core Audio API Master Volume Control.

I hope this helps.

Regards,

 

Alex (Alejandro Campos Magencio)