private static bool setDefaultAudioDevice(string deviceId) { var client = new CPolicyConfigClient(); client.SetDefaultDevice(deviceId); var vclient = new CPolicyConfigVistaClient(); vclient.SetDefaultDevice(deviceId); return(true); }
private static bool setDefaultAudioDevice(string regKey, string deviceId, string deviceIdPrefix) { try { using (RegistryKey deviceKey = Registry.LocalMachine.OpenSubKey(regKey + @"\" + deviceId, true)) { Byte[] timestamp = DateToBytes(DateTime.Now.ToUniversalTime()); deviceKey.SetValue("Role:0", timestamp); deviceKey.SetValue("Role:1", timestamp); deviceKey.SetValue("Role:2", timestamp); } } catch (Exception e) { throw; } //After changing the registry, use IPolicyConfig->SetDefaultEndPoint to ensure that notifications go out to all running applications CPolicyConfigClient client = new CPolicyConfigClient(); client.SetDefaultDevice(deviceIdPrefix + deviceId); CPolicyConfigVistaClient vclient = new CPolicyConfigVistaClient(); vclient.SetDefaultDevice(deviceIdPrefix + deviceId); return true; }