2014-10-20 101 views
0

我有一個系統有兩個PnP揚聲器插入。它們都是同一類型的設備。一個將安裝在前面,一個將安裝在後面。製造商可以添加一些驅動程序級別ID,以便我們知道哪個是哪裏。當我設置播放的音頻輸出時,我需要能夠確定從設備信息中獲取哪個設備。如何從XAudio2獲取有關特定pnp揚聲器的驅動程序信息設備詳細信息

當我從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 

我有以下特性: DEVICEID 顯示名稱 OUTPUTFORMAT 角色

對於這兩個設備,一切都是一樣的顯示名稱將具有與該實例關聯的數字號碼。我們將安裝許多這些設備,因此我無法保證這些數字將保持一致。

我想這個設備實例與一些司機的電平值,讓我知道什麼物理設備中插入相關。

然後我打算用在Win32_SoundDevice或某些WMI查詢類似的東西但我找不到從XAudio2設備詳細信息到Wmi聲音設備實例的任何常用鏈接。

任何幫助,將不勝感激。我知道這可以做到,因爲我看到他們在Windows聲音管理中做到了。

回答

0

答案是,你需要將設備ID映射到註冊表,然後映射註冊表項,以Win32_PnPSignedDriver條目:

1日從設備獲取詳細的設備ID:

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

一旦你有編號,我們可以得到這個位於註冊表項: SOFTWARE \微軟\的Windows \ CurrentVersion \ MMDevices \音頻\渲染\ 「CLASSID」 \屬性

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(); 
相關問題