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.