【发布时间】:2011-03-23 13:05:36
【问题描述】:
您好,我正在使用 C# 在 Windows 中创建基于桌面的应用程序。
我必须在 2 个不同的组合框中显示所有可用音频和视频设备的列表。 从组合框中选择任何设备都会将该特定设备设置为默认设备
我正在使用 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?
谁能指出我正确的方向?
【问题讨论】:
-
也许你应该有管理员权限。以管理员身份运行。