2010-02-01 15 views

Respuesta

11

No hay API pública que le permite cambiar el dispositivo de audio predeterminado, que es la funcionalidad que se considera estar bajo el control de los usuarios. Este siempre ha sido el caso en Windows.

Habiendo dicho eso, si buscas en la web, hay un número de personas que han diseñado ingeniería inversa de las API que se usan en Windows Vista para hacer esto, pero no voy a señalarte a ellas (el reverso las API diseñadas son API internas no compatibles y pueden cambiar sin previo aviso por parte de Microsoft). Usted utiliza estas soluciones bajo su propio riesgo.

+1

http://sdae.codeplex.com/ - Lo usé y funcionó. –

+0

que convierte el código del enlace en el comentario anterior en a C# y añade un poco de materia, se puede encontrar aquí, así: https://github.com/zivsha/SoundControl – ZivS

13

System Tray Audio Device Switcher usa "Software\Microsoft\Multimedia\Sound Mapper", "Playback" para establecer el índice del dispositivo de sonido que se obtuvo al enumerar los dispositivos. mciSendCommand de "WINMM.DLL" también se utiliza

En este source code se encuentran las claves de registro utilizadas para lograrlo.

Si esto no funciona, usted podría dar Process Monitor una oportunidad y supervisar todas las actividades de registro de las ventanas cuando cambie el dispositivo por defecto. En mi instalación de Vista del panel de control twiddles con "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\"

Para Vista ver http://www.vistaaudiochanger.com/

5

Realmente no sé si alguien todavía necesita esto, pero aquí está mi solución. En realidad, es para el dispositivo de captura, pero se puede cambiar fácilmente al dispositivo de renderizado.

En él se establecen los valores de registro 3 en la clave del dispositivo a la hora actual. Magia, pero así es como funciona. Nota: sólo se probó en Win7 x64

void SetDefaultRecordDevice(tstring strDeviceName){ 
    const int BUFF_LEN = 260; 
    //HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{79434968-09f6-4dff-8086-c5e618b21473}\Role:0: 
    //"DE 07 08 00 06 00 10 00 15 00 38 00 1E 00 48 03" 
    HKEY hkCaptureDevices; 
    RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio\\Capture") , 0, KEY_ENUMERATE_SUB_KEYS | KEY_WOW64_64KEY, &hkCaptureDevices); 
    TCHAR lpwstrDeviceGuidKey[BUFF_LEN]; 
    DWORD dwDeviceGuidKeySize = BUFF_LEN; 
    for(int i=0;RegEnumKeyEx(hkCaptureDevices, i, lpwstrDeviceGuidKey, &dwDeviceGuidKeySize, 0, 0, 0, 0) != ERROR_NO_MORE_ITEMS; ++i){ 
     dwDeviceGuidKeySize = BUFF_LEN; 
     HKEY hkProps; 
     RegOpenKeyEx(hkCaptureDevices, (tstring(lpwstrDeviceGuidKey) + _T("\\Properties")).c_str() , 0, KEY_READ | KEY_WOW64_64KEY, &hkProps); 
     TCHAR data[BUFF_LEN]; 
     DWORD dwDataSize = BUFF_LEN; 
     if(RegQueryValueEx(hkProps, _T("{a45c254e-df1c-4efd-8020-67d146a850e0},2"), 0, 0, (LPBYTE)data, &dwDataSize) != ERROR_SUCCESS){ 
      continue; 
     } else { 
      tstring strCurrentDeviceName(data); 
      // TODO név általánosítás 
      if(strDeviceName == strCurrentDeviceName){ 
       HKEY hkGuid; 
       RegOpenKeyEx(hkCaptureDevices, lpwstrDeviceGuidKey , 0, KEY_READ | KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_64KEY | KEY_NOTIFY , &hkGuid); 

       time_t CurrentTime; 
       time(&CurrentTime); 

       time_t  now = time(0); 
       struct tm tstruct; 


       gmtime_s(&tstruct, &now); 
       // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime 
       // for more information about date/time format 

       char CustomRegistryDateValue[16]; 

       WORD year = tstruct.tm_year + 1900; 
       WORD month = tstruct.tm_mon+1; 
       WORD dayOfTheWeek = tstruct.tm_wday; 
       WORD day = tstruct.tm_mday; 
       WORD hour = tstruct.tm_hour; 
       WORD minute = tstruct.tm_min; 
       WORD second = tstruct.tm_sec; 
       WORD millisec = 0x0; // hasrautés 

       int k = 0; 
       *((WORD*)CustomRegistryDateValue + k++) = year; 
       *((WORD*)CustomRegistryDateValue + k++) = month; 
       *((WORD*)CustomRegistryDateValue + k++) = dayOfTheWeek; 
       *((WORD*)CustomRegistryDateValue + k++) = day; 
       *((WORD*)CustomRegistryDateValue + k++) = hour; 
       *((WORD*)CustomRegistryDateValue + k++) = minute; 
       *((WORD*)CustomRegistryDateValue + k++) = second; 
       *((WORD*)CustomRegistryDateValue + k++) = millisec; 

       RegSetValueExA(hkGuid, ("Role:0"), 0, REG_BINARY, (LPBYTE)CustomRegistryDateValue, 16); 
       RegSetValueExA(hkGuid, ("Role:1"), 0, REG_BINARY, (LPBYTE)CustomRegistryDateValue, 16); 
       RegSetValueExA(hkGuid, ("Role:2"), 0, REG_BINARY, (LPBYTE)CustomRegistryDateValue, 16); 
       RegFlushKey(hkGuid); 
       RegCloseKey(hkGuid); 
      } 
     } 
     RegCloseKey(hkProps); 
    } 
    RegCloseKey(hkCaptureDevices); 
} 
+0

Gran! Trabajando incluso en Windows 10 –

+0

En realidad, esto no funciona, al menos no en Windows 7/64. El cuadro de diálogo Sonido/Grabación muestra el cambio en el dispositivo de grabación predeterminado (si lo vuelve a cargar al menos), pero (reabierto) las funciones de WaveIn aún obtienen sus datos del dispositivo anterior. Entonces parece ser un cambio cosmético, internamente las cosas no se actualizan. Supongo que necesita más magia. –

Cuestiones relacionadas