试一试这个
ManagementObjectSearcher mo = 
      new ManagementObjectSearcher("select * from Win32_SoundDevice");foreach (ManagementObject soundDevice in mo.Get())
{
     String deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
     String name  = soundDevice.GetPropertyValue("Name").ToString();  //saving the name  and device id in array

解决方案 »

  1.   

    On Vista and Win7 you could use the MMDevice API IMMDeviceEnumerator::GetDefaultAudioEndpoint, and then use MMDevice::GetId to get the string describing this device.转自
    http://stackoverflow.com/questions/1809190/how-to-identify-the-default-audio-devices-from-a-net-application
      

  2.   

    谢谢。
    我在winodws 7上试验了IMMDeviceEnumerator::GetDefaultAudioEndpoint, and then use MMDevice::GetId的方法,参考了网上的一个调整音量的例子。
    结果IMMDeviceEnumerator::GetDefaultAudioEndpoint执行正常,能够得到device,下一步MMDevice::GetId取不到值。
    明天再试试waveOutGetDevCaps using deviceID=WAVE_MAPPER (-1) 的方法。再次感谢。
      

  3.   

    waveOutGetDevCaps using deviceID=WAVE_MAPPER (-1) 的方法不行。最后用vb.net的IMMDeviceEnumerator::GetDefaultAudioEndpoint实现了想要的功能。谢谢