使用WMI枚举音频输入设备

时间:2016-03-22 16:17:52

标签: c# wmi naudio microphone

我在我的C#项目中使用NAudio,我正在寻找一种枚举音频输入设备(麦克风等)的方法,所以我可以得到它们的全名(不仅是我能用的31个字符长的名字)从NAudio获得)。我经历了几个人们用WMI枚举音频输出设备的帖子:

ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
       "SELECT * FROM Win32_SoundDevice");

ManagementObjectCollection objCollection = objSearcher.Get();

是否可以通过这种方式枚举输入设备?

由于

2 个答案:

答案 0 :(得分:3)

要探索WMI查询,您可以使用为您生成WMI代码的工具。您将拥有大量WMI管理类来获取信息。 您可以从Microsoft下载中心here

下载该工具

几年前我写了一篇关于使用WMI管理服务进行管理的博客post。希望这会给你一个良好的开端。

此工具生成的片段,用于获取设备上已安装声卡的列表。

 public static void Main()
 {
     try
     {
         ManagementObjectSearcher searcher =
             new ManagementObjectSearcher("root\\CIMV2",
             "SELECT * FROM Win32_SoundDevice");

         foreach (ManagementObject queryObj in searcher.Get())
         {
             Console.WriteLine("-----------------------------------");
             Console.WriteLine("List of sound cards installed");
             Console.WriteLine("-----------------------------------");
             Console.WriteLine("ProductName: {0}", queryObj["ProductName"]);
             Console.WriteLine("Availability: {0}", queryObj["Availability"]);
             Console.WriteLine("Caption: {0}", queryObj["Caption"]);
             Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj["ConfigManagerErrorCode"]);
             Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj["ConfigManagerUserConfig"]);
             Console.WriteLine("CreationClassName: {0}", queryObj["CreationClassName"]);
             Console.WriteLine("Description: {0}", queryObj["Description"]);
             Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
             Console.WriteLine("DMABufferSize: {0}", queryObj["DMABufferSize"]);
             Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);
             Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);
             Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
             Console.WriteLine("LastErrorCode: {0}", queryObj["LastErrorCode"]);
             Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
             Console.WriteLine("MPU401Address: {0}", queryObj["MPU401Address"]);
             Console.WriteLine("Name: {0}", queryObj["Name"]);
             Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
             Console.WriteLine("PowerManagementSupported: {0}", queryObj["PowerManagementSupported"]);
             Console.WriteLine("Status: {0}", queryObj["Status"]);
             Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
             Console.WriteLine("SystemCreationClassName: {0}", queryObj["SystemCreationClassName"]);
             Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);
         }
     }
     catch (ManagementException e)
     {
        Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
     }
 }

这是输出 -

-----------------------------------
List of sound cards installed
-----------------------------------
ProductName: Realtek High Definition Audio
Availability:
Caption: Realtek High Definition Audio
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: Realtek High Definition Audio
DeviceID: HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_103C304A&REV_1001\4&3867FD9A&0&0001
DMABufferSize:
ErrorCleared:
ErrorDescription:
InstallDate:
LastErrorCode:
Manufacturer: Realtek
MPU401Address:
Name: Realtek High Definition Audio
PNPDeviceID: HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_103C304A&REV_1001\4&3867FD9A&0&0001
PowerManagementSupported: False
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: PC-2322Q1

答案 1 :(得分:0)

这些是声音设备,因此它包括输入和输出设备。声卡可以有0个或更多输出和0个或更多输入。