Slapping the Windows Master Volume

November 29, 2015 - .NET, C#, Programming

On a recent Forum post, I was intrigued by the idea of being able to control the Windows Master Volume Programmatically. In that particular case, the intent was to allow scripting of the volume for user login and logoff.

The result was a rather straightforward program intended for use on the command line for setting and retrieving the current master system volume. I’ve made the source Available on Github and also put up an installer download here.

My initial investigations ended up with code that was able to retrieve the volume, but not set it. The approach taken in that case defined only a single interface method for the interface in question, with a strange “vtable skip” type of method. I’m not sure if that is a special syntax or what, but I ended up looking elsewhere after a few attempts to add the appropriate method to set the system volume.

In my searches, I found a library intended to wrap the Core Audio API to allow it to be accessed from a .NET program, which can be found on CodePlex as well as a (seemingly more recent, based on commit messages) Github.

Once I had that in place, it was merely a case of wiring it all together. Thankfully, since the program is relatively straightforward it is small enough (IMO) to slap it right here for convenience:

Basically it takes the default EndPoint and changes or sets it’s volume. Nothing too fancy. Ideally, I would clean it up code-wise and also implement additional features- such as manipulating the audio of other programs – which could make it useful for certain scripting uses.

Have something to say about this post? Comment!