C# Detecting sound card
<p>C# 2008</p>

<p>I am using the code below to find out if the user has a sound card install or not. I have found 2 methods and wondering if one is better than the other. Is there anything better than the ones I have posted?</p>

<p>I am detecting on a windows desktop that this running XP, Vista, and Seven.</p>

<p>Many thanks for any advice,</p>

<pre><code>public partial class Form1 : Form
{
    [DllImport("winmm.dll", SetLastError = true)]
    public static extern uint waveOutGetNumDevs();

    public Form1()
    {
        InitializeComponent();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (waveOutGetNumDevs() != 0)
        {
            Console.WriteLine("The sound card is detected");
        }
        else
        {
            Console.WriteLine("No sound card");
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ManagementObjectSearcher searcher = 
            new ManagementObjectSearcher("Select ProductName from Win32_SoundDevice");

        foreach (ManagementObject device in searcher.Get())
        {
            Console.WriteLine("Sound card {0}", 
                device.GetPropertyValue("ProductName"));

        }


    }
}
</code></pre>
