title: How to associate a USB headsets microphone and earphone/speaker
body: <p><strong>Background</strong></p>
  
  <p>I need to display a list of connected headsets (combined microphone and earphone) in a softphone application. For testing I have the following devices:</p>
  
  <ul>
  <li>Jabra PRO 9470</li>
  <li>Plantronics BT300M</li>
  <li>Logitech G430 Gaming Headset</li>
  </ul>
  
  <p>The user should be able to select a headset from a <code>ComboBox</code>, without selecting the microphone and earphone separately.</p>
  
  <p><strong>The information</strong></p>
  
  <p>I know where to find the information (in Windows) about the microphone and earphone, but I have not been able to get it using <code>WMI</code> or <code>MMDevice API</code>.</p>
  
  <p>To find the information, right click on <code>Sound</code> (Speaker icon) in the right side of the taskbar and select <code>Playback devices</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/x9tyd.png" alt="Headset properties"></p>
  
  <ol>
  <li>Open the properties window by double clicking or click on <code>Properties</code>.</li>
  <li>Click the <code>Properties</code> button on the properties window.</li>
  <li>Click the <code>Details</code> tab and find the <code>Children</code> property in the <code>ComboBox</code>.</li>
  </ol>
  
  <p>This will give me the following information:</p>
  
  <pre><code>SWD\MMDEVAPI\{0.0.0.00000000}.{f2e09e37-8389-46c4-8b2b-53e08b874399}
  SWD\MMDEVAPI\{0.0.1.00000000}.{3402ee6e-d862-47ca-8ab8-bb8254216032}
  </code></pre>
  
  <p>The first line matches my <code>Headset Earphone (Jabra PRO 9470)</code> and the second <code>Headset Microphone (Jabra PRO 9470)</code>.</p>
  
  <p>To get the same information in C#, I'm loop through the <a href="https://msdn.microsoft.com/en-us/library/aa394505%28v=vs.85%29.aspx" rel="nofollow noreferrer">Win32_USBControllerDevice</a> class and outputting all values containing "MMDEVAPI". On my PC it will return 6 values (3 x microphones, 3 x earphones).</p>
  
  <pre><code>foreach (var device in new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get())
  {
      foreach (var property in device.Properties)
      {
          // Gets the value of the property on the device.
          var value = property.Value == null ? string.Empty : property.Value.ToString();
  
          if (value.IndexOf("mmdevapi", StringComparison.OrdinalIgnoreCase) &gt; -1)
          {
              // Output connected USB microphones and earphones.
              Console.WriteLine(property.Value);
          }
      }
  }
  </code></pre>
  
  <p>For reference, the above code will output:</p>
  
  <pre><code>\\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.0.00000000}.{F2E09E37-8389-46C4-8B2B-53E08B874399}"
  \\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.1.00000000}.{3402EE6E-D862-47CA-8AB8-BB8254216032}"
  \\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.0.00000000}.{985F2B5C-2EE2-4733-BBD6-48BFDE2D5582}"
  \\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.1.00000000}.{71D824EA-DAE9-4F0D-B673-4425385E3777}"
  \\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.0.00000000}.{D29C0970-D515-4F91-9924-F0063CF1A196}"
  \\PC9018\root\cimv2:Win32_PnPEntity.DeviceID="SWD\\MMDEVAPI\\{0.0.1.00000000}.{C4B331E2-C56B-4D9B-A486-2ED6C11FDB8C}"
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>My big problem now is, how do I associate the correct headsets microphone and earphone into a <code>Headset</code> object?</p>
  
  <p><strong>The attempts</strong></p>
  
  <p>I have tried searching Google and StackOverflow for an answer or hints, but I cannot find any common ground or relationship between the microphone and earphone using <code>WMI</code> or <code>MMDevice API</code>.</p>
  
  <p>If there is a way to create a <code>Dictionary&lt;string, List&lt;string&gt;&gt;</code> where the <code>Key</code> is something unique to the physical device or USB port, and the <code>Value</code> is a list of associated <code>Win32_PnPEntity.DeviceID</code>, then I cannot find it.</p>
  
  <p>In the spirit of <em>Star Wars Day</em> in a few days: "<em>Help me, StackOverflow. You are my only hope.</em>"</p>