【问题标题】:How to get driver information about a specific pnp speaker given the information from XAudio2 Device Details给定来自 XAudio2 设备详细信息的信息,如何获取有关特定 pnp 扬声器的驱动程序信息
【发布时间】:2014-12-15 11:14:08
【问题描述】:

我有一个插入了两个 PnP 扬声器的系统。它们都是同一类型的设备。一个安装在前面,一个安装在后面。可以让制造商添加一些驱动程序级别 ID,以便我们知道哪个在哪里。当我设置播放的音频输出时,我需要能够通过获取设备信息来确定我正在查看的设备。

当我从 XAudio2 获取设备信息时:

var deviceCount = _xAudio2Instance.DeviceCount;

        for (int i = 0; i < deviceCount; i++)
        {
            var device = _xAudio2Instances.GetDeviceDetails(i);
            Console.WriteLine("Sound: {0},{1},{2}", device.DeviceId, device.DisplayName, device.Role);

给我这样的输出:

Sound: {0.0.0.00000000}.{c55aa510-37ed-4139-a8bd-d0783eb07d5c},Speakers (Realtek High Definition Audio),11

Sound: {0.0.0.00000000}.{36cda8f6-e5b1-4c5f-877e-cf9b3a4a9ff7},Speakers (4- USB PnP Sound Device),DefaultCommunicationsDevice

Sound: {0.0.0.00000000}.{f562f43b-ba1f-489f-bf00-cf99e54a7513},Speakers (2- USB PnP Sound Device),NotDefaultDevice

我有以下属性: 设备编号 显示名称 输出格式 角色

对于这两个设备,除了显示名称之外,其他所有设备都相同,显示名称将具有与该实例相关联的数字编号。我们将安装许多这样的设备,所以我不能保证这些数字是一致的。

我正在尝试将此设备实例与一些驱动程序级别的值相关联,以便我知道插入了什么物理设备。

然后我打算在 Win32_SoundDevice 上使用一些 WMI 查询或类似的东西,但我找不到从 XAudio2 设备详细信息到 Wmi 声音设备实例的任何通用链接。

任何帮助将不胜感激。我知道这是可以做到的,因为我看到他们在 Windows 声音管理中做到了。

【问题讨论】:

    标签: c# audio wmi


    【解决方案1】:

    答案是你需要将设备id映射到Registry,然后将注册表项映射到Win32_PnPSignedDriver entry:

    第一次从设备详细信息中获取设备 ID:

    var device = _xAudio2Instances[TchDevice.Core].GetDeviceDetails(i);
    classId = device.DeviceId.Replace("{0.0.0.00000000}.", "");
    

    一旦您有了 id,我们就可以在以下位置获取此注册表项: SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\"classId"\Properties

    RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,RegistryView.Registry64);
    
    Microsoft.Win32.RegistryKey key = localKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio\\Render\\" + classId + "\\Properties");
    
    var searchKey = key.GetValue("{b3f8fa53-0004-438e-9003-51a46e139bfc},2").ToString().Split('.')[1];
    

    获得 searchKey 后,您就可以获得 Win32_PnPSignedDriver 条目:

    var mgmentsearcher = "SELECT * FROM Win32_PnPSignedDriver WHERE DeviceID like '%" + searchKey.Replace("\\", "\\\\") + "%'";            ManagementObjectCollection collection;
    
    using (var searcher = new ManagementObjectSearcher(mgmentsearcher))
    collection = searcher.Get();
    
    foreach (var device in collection)
    {
        var properties = device.Properties;
    
        var propertyEnumerator = properties.GetEnumerator();
    
        while (propertyEnumerator.MoveNext())
        {
            var p = (PropertyData)propertyEnumerator.Current;
            Console.WriteLine("Property {0}, Value: {1}", p.Name, p.Value);
        }
    }
    
    collection.Dispose();
    

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 1970-01-01
      • 2020-11-04
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      • 2017-07-30
      相关资源
      最近更新 更多