I try to get a list of computers that record devices, programmatically, and then change the default value, I managed to do this with playback devices in the code below, however I would like to do this with recording devices.
This is a list of devices that returns the code below:

These are the devices that I want to see and modify:

class Program
{
static void Main(string[] args)
{
MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
MMDevice DefaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
MMDevice SecondaryDevice = null;
PolicyConfigClient client = new PolicyConfigClient();
Console.WriteLine("-----------------------------------");
Console.WriteLine("List of devices");
Console.WriteLine("-----------------------------------");
for (int i = 1; i < devices.Count; i++)
{
if (devices[i].ID != DefaultDevice.ID)
{
SecondaryDevice = devices[i];
}
Console.WriteLine(devices[i].FriendlyName);
Console.ReadLine();
}
Console.WriteLine("Default Device");
Console.WriteLine("-----------------------------------");
Console.WriteLine(DefaultDevice.FriendlyName);
Console.ReadLine();
Console.WriteLine("Secondary Device");
Console.WriteLine("-----------------------------------");
Console.WriteLine(SecondaryDevice.FriendlyName);
Console.ReadLine();
client.SetDefaultEndpoint(SecondaryDevice.ID, ERole.eCommunications);
client.SetDefaultEndpoint(SecondaryDevice.ID, ERole.eMultimedia);
client.SetDefaultEndpoint(SecondaryDevice.ID, ERole.eConsole);
DefaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
Console.WriteLine("New Default Device");
Console.WriteLine("-----------------------------------");
Console.WriteLine(DefaultDevice.FriendlyName);
Console.ReadLine();
}
}
source
share