22

I want to be able to change the default audio output device on Windows 7 programatically using C# (and probably some underlying Win32 API calls, as well). I've already done my homework, and I've heard a lot of mixed comments from different sources, so I wanted to ask this question again to get a straight answer. Is this actually possible (through any means)? If so, how would I go about doing this?

And please do not suggest a solution with "AutoIt" or some other similar program... this is a C#/.NET-specific question.

2
  • Good odds that you'll get just more mixed comments from yet another source. Here's one: only a user selects the audio device she wants to listen to. May 30, 2011 at 18:37
  • 4
    +1 I was thinking of programming this myself. I really hate switching between my headphones and HDMI output.
    – Kugel
    May 30, 2011 at 18:38

2 Answers 2

17

A little up-to-date answer, which is compatible with Windows 10.

This program is able to do it in a beautiful manner (hotkey to switch between pre-selected devices) and is written on C# : SoundSwitch on GitHub

Some reverse engineering should get you there (for my use this program was just perfect as it is).

It makes use of that library (same author) which is in C++ : AudioEndpointLibrary on GitHub

So if you know C++ (which I don't enough), you might go further in the analysis of how it works. Or just use the library like SoundSwitch does.

1
  • 1
    Just a note about SoundSwitch: sometimes it is unreliable as it sets audio devices as communication devices instead of audio output and sometimes devices are forgotten from its system tray menu. But it's a start.
    – mattshu
    Jul 10, 2018 at 19:26
14

Just in case anyone stumbles across this thread in the future... here's some C++ code that'll do it by calling some undocumented Win32 APIs. This can be compiled into an EXE and then called silently from a .NET application, so you could build a .NET program around this code.

http://web.archive.org/web/20190317012739/http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/

3
  • 1
    It was working for Win 8.1 but unfortunatly it is not working anymore with windows 10, any solutions? Sep 17, 2015 at 17:59
  • You can check my answer for something that works with W10 !
    – Mickael V.
    May 25, 2016 at 16:51
  • 3
    this link is dead Jul 22, 2019 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.