您好我正在使用C#在Windows中創建一個基於桌面的應用程序。獲取音頻設備列表,並選擇一個使用C#
我必須在兩個不同的組合框中顯示所有可用音頻的列表&視頻設備。 從組合框中選擇任何設備會將該特定設備設置爲默認設備
我正在使用WMI。
代碼來獲取可用音頻設備列表:
ManagementObjectSearcher mo =
new ManagementObjectSearcher("select * from Win32_SoundDevice");
foreach (ManagementObject soundDevice in mo.Get())
{
String deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
String name = soundDevice.GetPropertyValue("Name").ToString();
//saving the name and device id in array
}
,如果我嘗試設置這樣的裝置:
using (RegistryKey audioDeviceKey =
Registry.LocalMachine.OpenSubKey(audioDevicesReg
+ @"\" + audioDeviceList.SelectedText.ToString(), true)){}
我得到異常:
System.Security.SecurityException occurred in mscorlib.dll
現在我有幾個問題:
1) How to set the selected device as the default audio device?
2) The array contains device name as : "High Definition audio device"
even when I have attached a headset.
3) I want the list as speaker,headset etc...How to get that?
有人能指點我嗎?
也許你應該擁有管理員權限。以管理員身份運行。 – 2017-07-25 10:33:16