views:

1245

answers:

2

How can I programatically change the default audio device on a vista / win 7 system? Using C# or a Win API call?

+8  A: 

The WinMM API should provide the functionality that you request.

You would use the DRVM_MAPPER_PREFERRED_SET message, which is sent with waveOutMessage() function.

Documentation: http://msdn.microsoft.com/en-us/library/aa909789.aspx

However, if you are trying to send the waveform sound out yourself, you should look at the WinMM.Net library.

http://winmm.codeplex.com

John Gietzen
All I need to do is change the sound device on Windows, so that all audio routes through that device. Essentially I have a lot of sound devices on my system, and I want to replace the default sys tray app, so that I don't need to right click , open the device manager each time I need to switch a device. Will this API do this?
JL
Yes, You can set the default audio playback device in XP with the DRVM_MAPPER_PREFERRED_SET message, which is sent with waveOutMessage(). This doesn't work in Vista. I am researching.
John Gietzen
Thanks, I think this last link will work, it should port to win 7 hopefully!
JL
Love that last link! It's been driving nuts in Win7 having to launch the Playback devices dialog every time I want to switch from headphones to speakers, and vice-versa. Much easier now. Thanks!
Ecyrb
A: 

Ecyrb: It sounds like you were able to change the default audio device in Win7 using winmm.net? I have built the Winmm.net project from the link in Win7, but I cannot find a method that will change the default system device? Can you please point me in the right direction?

Trevor Meyer