none
Setting Default Sound Device programmatically in Vista

    Question

  • Hi,

    In my application I need to set programmatically the default sound device (playback device), on XP there is a way changing the HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Playback value, but on Vista this isn't working.
    Using the new Core Audio API there is no way to change the default sound device, only to get it with GetDefaultAudioEndpoint() method from IMMDeviceEnumerator interface.
    I tried to fiigure out which keys/values are changed in the registry when I manually change the default device. Actually there are 3 binary values changed "Role:0", "Role:1" and "Role:2" under  the following key: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{GUID}".
    I guess these three valuse are comming from the role of this sound device: console, multimedia  and communcations.
    Now these values are binary values and I cannot figure out how they are changed, only that they must be greater for the default device.

    Maybe someone could help me to figure out how these values are calculated or another solution to change the default device on Vista ?

    Best regards,
    Boby
    Monday, December 04, 2006 3:23 PM

All replies

  • Hi Boby,

                        I want also same thing as you have explained in your query. If you have some solution then please replay me.

    Thursday, December 21, 2006 11:40 AM
  • It is just a timestamp.

    Ex. D7:07:01:00:05:00:0C:00:0A:00:17:00:26:00:BB:00

    07 means year 2007

    01 means Jan.

    0C mean 12

    ....

    So it represents 2007/1/12 10:17:26 

     

    Friday, January 12, 2007 10:33 AM
  • Sorry! Some mistakes.

    D7:07 means year 2007. D7 is the low byte of 2007 and 07 is the hight byte.

    05 means Friday.

    Tuesday, January 16, 2007 6:16 AM
  • I have a Plantronics USB headset which gets set as default device the second it gets plugged in. This is annoying as I use this headset for skype only and don't want every other sound in it. When I select my primary soundcard as default and click ok, then open sound properties again, Plantronics headset is back as default sound device.  I think it's bad that this problem has been known for so long and still haven't been fixed.
    Friday, January 19, 2007 11:52 PM
  • We have the similar problem.. please rush to give a solution to switch the default audio device automatically.

    If you find the solution, could you let me know how to solve it ?

    e-mail address is tory45@enus.co.kr

     

    • Proposed as answer by Dean Brady Wednesday, February 16, 2011 6:09 PM
    Thursday, February 22, 2007 6:20 AM
  • We are writing an application that uses a Bluetooth headset as well.  Unfortunately we are experiencing the same problem, when the headset is activated it becomes the default recording and playback device.  We are only using the microphone portion of the headset and wish all sound to continue to be played through the original default speakers.  Could you please let us know how it is either 1) possible to change the default sound device back programmatically or 2) stop windows from automatically changing the the default sound devices to the Bluetooth headset when it connects.  Seems like this is a fairly common problem.  PLEASE HELP.
    Tuesday, July 24, 2007 4:50 PM
  • After you change a RegValue try to restart Windows Explorer. That maybe help.

    ' example in VBscript

    ImeComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & ImeComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'")
    For Each objProcess in colProcessList
        objProcess.Terminate()
    Next



    Wednesday, August 15, 2007 7:05 AM
  • For Windows XP only , it worked changing the SOUNDMAPPER device

    modifying the registry programatically using  the following way:

     

    Locate  HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Playback value and

    EXPORT the registry branch for each SOUND DEVICE existing

    (selected one by one via ControlPanel + Sound and Audio Device Properties) , generating n REG files

    - in my case, having 2 sound boards and one USB device  were :

    CMediaWaveDevice.reg

    CrystalSoundFusion(tm)Device.reg

    USBPhoneDevice.reg

    A simple click over the REG file in WindowsExplorer ( that could be launched by a general shortcut)

    would insert the respective SOUND DEVICE in the registry and Select the new SoundDevice.

    These REGfiles could be called programmatically , for example, by the following Delphi Code below:

    Description of Delphi Form (dfm) and Unit (Unit1.pas):

     

    In a Form with a Listbox with each Regfile for any SOUND DEVICE ,

    select the desired item, and will be called a routine ShellExecute that  installs  the regfile in the registry.

     

    Code Block

     

    UNIT1>>>>>>>>>>>>>>>>> Unit1.pas

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ShellAPI;
    const
        dev0='CMediaWaveDevice.reg';
        dev1='USBPhoneDevice.reg';
        dev2='CrystalSoundFusion(tm)Device.reg';
    type
      TForm1 = class(TForm)
        Label1: TLabel;
        ListBox1: TListBox;
        cmd: TEdit;
        btExec: TButton;
        btMount: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure btMountClick(Sender: TObject);
        procedure btExecClick(Sender: TObject);
        procedure ListBox1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;
      path_app,path_regfiles:string;

    implementation

    {$R *.DFM}

    procedure TForm1.FormCreate(Sender: TObject);
    begin
         path_app:= getcurrentdir;
         path_regfiles:=path_app+'\..\';

         if not fileexists( path_regfiles+dev0)
            then
            begin
             showmessage('Device Reg File not found');
             halt;
            end;
    end;

    procedure TForm1.FormActivate(Sender: TObject);
    begin
         listbox1.ItemIndex :=1;
         listbox1.ItemIndex :=0;
         listbox1.SetFocus;
         btMountClick(Sender);
    end;

    procedure TForm1.btMountClick(Sender: TObject);
    var s:string;
    begin
         case  listbox1.ItemIndex of
          0: s:=dev0;
          1: s:=dev1;
          2: s:=dev2;
         end;
         cmd.text:= s;
    end;
    procedure TForm1.btExecClick(Sender: TObject);
    begin
         ShellExecute(handle,'open',Pchar(cmd.text),'', Pchar(path_regfiles), SW_SHOWNORMAL);
    end;

    procedure TForm1.ListBox1Click(Sender: TObject);
    begin
         btMountClick(Sender);
    end;

    end.

     

    FORM>>>>>>>>>>>>>>>>> Unit1.dfm

    object Form1: TForm1
      Left = 192
      Top = 114
      Width = 313
      Height = 228
      Caption = ' Sound Mapper Device Selector'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      OnActivate = FormActivate
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Label1: TLabel
        Left = 40
        Top = 24
        Width = 145
        Height = 18
        Caption = 'PlaybackDevice'
        Font.Charset = ANSI_CHARSET
        Font.Color = clNavy
        Font.Height = -16
        Font.Name = 'Verdana'
        Font.Style = [fsBold]
        ParentFont = False
      end
      object ListBox1: TListBox
        Left = 32
        Top = 56
        Width = 161
        Height = 89
        Hint = #39'Click to Select Playback Device'#39
        ItemHeight = 13
        Items.Strings = (
          'C-Media Wave Device'
          'Generic USB Audio Device'
          'Crystal SoundFusion(tm)')
        ParentShowHint = False
        ShowHint = True
        TabOrder = 0
        OnClick = ListBox1Click
      end
      object cmd: TEdit
        Left = 24
        Top = 160
        Width = 185
        Height = 21
        TabOrder = 1
      end
      object btExec: TButton
        Left = 216
        Top = 160
        Width = 75
        Height = 25
        Caption = 'Select'
        TabOrder = 2
        OnClick = btExecClick
      end
      object btMount: TButton
        Left = 216
        Top = 128
        Width = 75
        Height = 25
        Caption = 'Mount'
        TabOrder = 3
        OnClick = btMountClick
      end
    end

     

     

     

     

     

     

    Monday, November 05, 2007 2:11 AM
  •  

    hi

       I am stucked in a deadly trap I want to select stereomix  or mic in VISTA programmatically and unable to find any thing regarding that..... could you please help me out in this context.

    Is there any so called API or something..... ... things were working pretty fine when i was with XP but the time i switched to VISTA , I am unable to carryon my things further.

     

    please please someone help me out.

     

     

     

    Wednesday, November 12, 2008 6:32 AM
  • Hi!!! I'm struggling to get this work!! did some1 manage to find a crack/hack ??? This topic on forum is old....if anyone came across a solution ? or what they did to get it work, somehow? Regards
    Tuesday, June 09, 2009 11:34 AM
  • I have found a solution for that.. this is using autoit 3.0 script.. its working.. have a look
    http://forum.codeproblem.com/c/how-to-set-default-audio-device-programmaticaly-in-c-on-windows-vista/msg20/#msg20
    I hope it will help you...
    Thanks
    Muhammad Ummar Iqbal Bhutta
    Thursday, September 10, 2009 10:58 AM