audio-device

How to identify the default audio device in Powershell?

流过昼夜 提交于 2021-02-10 18:25:39
问题 I am looking for a solution to get the default audio device via Powershell. In best case, it could work via embedded C#-code to directly use IMMDeviceEnumerator::GetDefaultAudioEndpoint (see here IMMDeviceEnumertor). But if it is easier to get this via RegKeys, then this is also OK. I have seen a couple of code-snippets reading the keys from HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render or \Capture, but I still struggle to identify the DEFAULT device. It seems, when I

Detect if headphones are plugged in or not via C#

只愿长相守 提交于 2019-11-27 19:52:36
There is no example how to detect if headphones are plugged in or not via C#. I assume should be some event for that... Does make sense to use WMI? ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\cimv2", "SELECT * FROM Win32_SoundDevice"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_SoundDevice instance"); Console.WriteLine("-----------------------------------"); Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]); } Would anyone be so pleased to provide it? Thank you

Detect if headphones are plugged in or not via C#

╄→гoц情女王★ 提交于 2019-11-27 04:24:29
问题 There is no example how to detect if headphones are plugged in or not via C#. I assume should be some event for that... Does make sense to use WMI? ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\cimv2", "SELECT * FROM Win32_SoundDevice"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_SoundDevice instance"); Console.WriteLine("-----------------------------------"); Console