C# – Adjust master volume in Vista and Windows 7

There are a lot of changes in Vista and Windows 7 in comparison with Windows XP, especially in programming field. Many code snippet which works perfectly, does not run under Vista/Windows 7 anymore, for example adjusting master volume. If you have already worked with master volume in Windows XP, maybe you use MixerControl for accessing system volume with following API.
– mixerClose
– mixerGetControlDetailsA
– mixerGetDevCapsA
– mixerGetID
– mixerGetLineControlsA
– mixerGetLineInfoA
– mixerGetNumDevs
– mixerMessage
– mixerOpen
– mixerSetControlDetails

Under Vista/Windows 7, we can not use this API anymore because volumes have been individualized in Vista which means for the most part an application changing the waveOut volume has no affect on other applications. In Vista/Windows 7, we must use another APIs which is COM based.
– MMDevice API: The Windows Multimedia Device (MMDevice) API enables audio clients to discover audio endpoint devices, determine their capabilities, and create driver instances for those devices.
– WASAPI: The Windows Audio Session API (WASAPI) enables client applications to manage the flow of audio data between the application and an audio endpoint device.
– DeviceTopology API: The DeviceTopology API provides client applications with the ability to traverse the functional hardware topologies of audio rendering and capture devices. Through the interfaces and methods in the DeviceTopology API, clients can discover the functional subunits (for example, volume control) that lie along the data paths that lead to and from audio endpoint devices.
– The EndpointVolume API enables specialized clients to control and monitor the volume levels of audio endpoint devices.

Ray M. wrote a great article about how to use these APIs for adjusting system volume on CodeProject http://www.codeproject.com/KB/vista/CoreAudio.aspx . For more details you can read at that article. I just tested the available codes if they really work and stored both of methods into one project so that I can use later. The complete backup code you can download here “Adjust System Volume”.

UPDATE 04.03.2010
There are problems at synchronizing between volume and slider. No idea how to solve it!


  1. btw. your sliderbug gets fixed with:
    m_device.AudioEndpointVolume.MasterVolumeLevelScalar = (float)(sldVolume.Value / 100);

    just in case you didn’t figure it out yet 🙂

  2. Veeeeeery good piece of Code … Thanks a lot.

    The slider problem was a type conversion issue, but not the one as mentioned by Marvin. Correct instead the

    sldVolume.Value = (int)data.MasterVolume * 100;
    sldVolume.Value = (int)(data.MasterVolume * 100);

    otherwise the sldVolume.Value will always be zero.


Leave a comment

Your email address will not be published. Required fields are marked *