获取声音设备名称

Posted on 2019-01-20 21:24  努力成长静待花开  阅读(518)  评论(1编辑  收藏  举报

实现效果:

  

知识运用:

  ManagementObjectSearcher类和ManagementObject类

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            ManagementObjectSearcher VoiceDeviceSearcher = new ManagementObjectSearcher("select * from Win32_SoundDevice");
            foreach(ManagementObject  VoiceDeviceObject in VoiceDeviceSearcher.Get())
            {
                textBox1.Text=VoiceDeviceObject["Name"].ToString();
                textBox2.Text=VoiceDeviceObject["PNPDeviceID"].ToString();
            }
            button1.Enabled = false;
        }