1. I need list of all device names and types (playback or recording). How can I get them?
2. I also need to determine if device is Playback or Recording device.
By device names I mean names visible here under Playback and Recording tab (screenshot below). Im not familiar with audio under windows, i don't know if these devices are ASIO, DirectSound or something else.
My application should be comaptybile with Windows Vista/7/8, so I decided to use .NET 3.5, but I can use any .NET version supported by Windows Vista/7/8.
Edit: I tried to get these from WMI "SELECT * FROM Win32_SoundDevice", but this is not what I mean. It returns hardware devices, not devices visible in windows sound configuration.
Use How to enumerate audio out devices in c#:
ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
"SELECT * FROM Win32_SoundDevice");
ManagementObjectCollection objCollection = objSearcher.Get();
foreach (ManagementObject obj in objCollection)
{
foreach (PropertyData property in obj.Properties)
{
Console.Out.WriteLine(String.Format("{0}:{1}", property.Name, property.Value));
}
}
Related
On Windows IoT (but also on the normal Windows 10), you can enable keyboard filter and shell launcher.
I enabled UWF, KB-Filter and Shell Launcher.
Now, I can't get the parameters of my keyboardfilter with a simple C#.NET program.
ManagementScope scope = new ManagementScope(#"root\standardcimv2\embedded");
using (ManagementClass mc = new ManagementClass(scope.Path.Path, "WEKF_Settings", null))
{
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
}
}
The UWF_Filter is working. WEKF_Settings and WESL_UserSetting are not working, even if they are enabled on the OS.
I get always the exception Provider Load Failure, even if the application is started as administrator.
In powershell, I get the class without any problem:
Get-CimClass wekf_settings \\.\root\standardcimv2\embedded | select -expand cimclassqualifiers
So the question: why can't I get the instances (with GetInstances()) in C# but only with powershell?
Just as info (if you get the same error):
The query fails also on Powershell, if this is 32-bit.
You need to compile the program as 64bit. Then the code will be able to query the keyboard filter.
This was the solution.
I am writing a small C# application to identify which type of display connect to pc
A Monitor
A TV screen
A projector
I try to do with
Screen.AllScreens
EnumDisplayDevices()
but it does not help anything.
When I use
var mbs = new ManagementObjectSearcher("Select * From CIM_LogicalDevice");
ManagementObjectCollection mbsList = mbs.Get();
I can get device id:
DISPLAY\OTMFB0E\4&9C24ACE&0&UID16843008
DISPLAY\DELD058\4&9C24ACE&0&UID50725632
But there is not any value which is used to identify between a normal monitor and a projector.
Is there any way to do?
Or which information will be different of these display types?
I want to use C# to retrieve the USB headset devices connected to PC. I tried the below solutions but didn't work:
Solution 1:
How to enumerate audio out devices in c#
I tried this but the device name appears as "(Generic USB Audio)" and not the actual name.
Solution 2:
How to get the default audio device?
Solution 3:
Detecting Audio Input & output devices connected to system
Solution 2 and Solution 3 gave me the below result:
The device name is truncated to 31 characters.
Eg: "Microphone (Sennheiser VOICE 689"
****Question: Is there any way I can get the complete name of the device?****
If you know it's an USB audio device, and assuming the driver is correctly written for the device, you could do:
foreach (ManagementObject drive in
new ManagementObjectSearcher(
"select Name from Win32_USBDevice where Service='usbaudio'").Get())
{
{
string s = drive["Name"].ToString();
// Continue
}
}
Addition
You're only getting 31 characters (technically 32) because the PInvoke to the native .DLLs use a char[32], so it can't return more than that; you won't get what you need from solution 1 & 2.
Also, I don't know why you can't use Win32_USBDevice, as I'm also using Win7 x64 and I'm having no problems. This link might help you.
Possible Alternate
You might be able to use the Win32_PnPEntity class:
foreach (ManagementObject drive in
new ManagementObjectSearcher(
"select Name from Win32_PnPEntity where Service='usbaudio'").Get())
{
{
string s = drive["Name"].ToString();
// Continue. Can look at Description, Caption, etc. too
}
}
I already tried Screen.AllScreen, SystemInformation.MonitorCount, and WMI but all of them failed.
My application runs as a windows service, hence no visual Form or UI. Both Screen.AllScreen and SystemInformation.MonitorCount returns 1 even when I have 2 monitors. If I run my application in console, it returns the correct count of display but my requirement is that my application to run as a windows service (no UI).
Thanks!
Found answer to my own question.
Still end up using WMI.
I was initially using Win32_DesktopMonitor giving a non-reliable answer.
Using this query:
"SELECT * FROM Win32_PnPEntity WHERE Service = 'monitor'"
WMI returns the correct monitor instance connected to my PC.
I went with Win32_PnPEntity because it represents the information for Plug and Play Devices in your Device Manager, which will show you when you have a monitors plugged in. The way the query works in "searcher" is more likely to be accurate than others since it uses the Like Operator. I do this because on 3 different computers the monitor entries in Device manager appeared differently. E.g. (Pnp-Monitor, Pnp Monitor (Standard), Generic Pnp Monitor).
private int CountMonitorsInstalled()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "select * from Win32_PnPEntity WHERE Name LIKE '%PnP%Monitor%'");
return searcher.Get().Count;
}
catch(Exception ex)
{
return 0;
}
}
Hi I am creating a desktop based application in windows using C#.
I have to show list of all available audio & video devices in 2 different combo boxes.
Selecting any device from combo box will set that particular device as the default one
I am using WMI.
Code to get list of available audio devices:
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
}
if i try to set the device like this:
using (RegistryKey audioDeviceKey =
Registry.LocalMachine.OpenSubKey(audioDevicesReg
+ #"\" + audioDeviceList.SelectedText.ToString(), true)){}
i get exception :
System.Security.SecurityException occurred in mscorlib.dll
Now I have few questions:
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?
can anybody point me in the right direction?
There is no documented mechanism for changing the default audio device.
That's because you're enumerating the physical audio devices, not the audio endpoints.
You want to use the IMMDeviceEnumerator API to enumerate the audio endpoints (speakers, etc).
Unfortunately there is no managed interop published by Microsoft for the IMMDeviceEnumerator API, you'll need to define your own (there are several definitions available on the internet).
I am answering too late to this question.. but it may be helpful for others.
Lync 2013 SDK provides DeviceManager class which list all the audio and video devices in collections
LyncClient.GetClient().DeviceManager.AudioDevices enumerates all the audio devices on the system
LyncClient.GetClient().DeviceManager.VideoDevices enumerates all the video devices on the system
So, one can set the device as:
LyncClient client = LyncClient.GetClient();
DeviceManager dm = client.DeviceManager;
dm.ActiveAudioDevice = (AudioDevice)dm.AudioDevices[0]; //or any other found after foreach
dm.ActiveVideoDevice = (VideoDevice)dm.VideoDevices[0]; //or any other found after foreach
HTH.