您好我正在使用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