2

I am trying to figure out how to detect whether a certain machine has speakers, headphones or a microphone plugged into it, using .NET C#.

I have been seeking for a possible way to achieve this but nothing seemed to work for me. I have came across the Microsoft.DirectX namespace which later on led me to writing the next method:

ManagementObjectSearcher mo = new ManagementObjectSearcher
                                         ("select * from Win32_SoundDevice");
int i = 0;
foreach (ManagementObject soundDevice in mo.Get())
{
    Console.WriteLine(soundDevice.GetPropertyValue("DeviceId"));
    Console.WriteLine(soundDevice.GetPropertyValue("Manufacturer"));
    Console.WriteLine("\n\n\n",i++);                 
}

Console.WriteLine("Total: {0}", i);

Sadly, the example above has printed a list of drivers for me, as it seems. I tested it out by plugging in and unplugging my speakers and my mic, but the amount of devices printed was the same regardless.

I'm wondering if there's any better way to track devices connected to the PC.

Flat Eric
  • 7,971
  • 9
  • 36
  • 45
Tommy Naidich
  • 752
  • 1
  • 5
  • 23
  • Did you check the [`Availability`](http://msdn.microsoft.com/en-us/library/aa394463(v=vs.85).aspx#properties) property on each device? – John Koerner Jul 10 '14 at 16:55
  • Console.WriteLine(soundDevice.GetPropertyValue("Availability")); doesn't seem to return anything at all. – Tommy Naidich Jul 10 '14 at 17:00
  • There's additional special hardware required in order to detect whether something is connected to the jack. Not all computers will have this. – Ben Voigt Jul 10 '14 at 18:43
  • @Ben Voigt Do you happen to know what is the name of that specific hardware which makes it possible for programs to determine whether or not a device is plugged in? – Tommy Naidich Jul 11 '14 at 10:17
  • "special"/"specific" as in "it serves no other purpose", not as in "there's only one approach" – Ben Voigt Jul 11 '14 at 17:51

0 Answers0