Change default audio device on Windows 7
Asked Answered
R

2

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.

Rosmunda answered 30/5, 2011 at 17:50 Comment(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.Clerc
+1 I was thinking of programming this myself. I really hate switching between my headphones and HDMI output.Beata
R
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/

Rosmunda answered 27/6, 2011 at 17:47 Comment(3)
It was working for Win 8.1 but unfortunatly it is not working anymore with windows 10, any solutions?Demirep
You can check my answer for something that works with W10 !Sever
this link is deadCockhorse
S
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.

Sever answered 25/5, 2016 at 16:51 Comment(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.Legal
R
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/

Rosmunda answered 27/6, 2011 at 17:47 Comment(3)
It was working for Win 8.1 but unfortunatly it is not working anymore with windows 10, any solutions?Demirep
You can check my answer for something that works with W10 !Sever
this link is deadCockhorse

© 2022 - 2024 — McMap. All rights reserved.