I did this test where I mute MS Edge =>
(to be improved, like replacing all if (SUCCEEDED(hr)) by a macro like in MS samples...)
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
IMMDeviceEnumerator* pDeviceEnumerator = NULL;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pDeviceEnumerator);
if (SUCCEEDED(hr))
{
IMMDevice* pDevice = NULL;
hr = pDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
if (SUCCEEDED(hr))
{
IAudioSessionManager2* pAudioSessionManager2 = NULL;
hr = pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (VOID**)&pAudioSessionManager2);
if (SUCCEEDED(hr))
{
IAudioSessionEnumerator* pAudioSessionEnumerator = NULL;
hr = pAudioSessionManager2->GetSessionEnumerator(&pAudioSessionEnumerator);
if (SUCCEEDED(hr))
{
int nSessionCount;
hr = pAudioSessionEnumerator->GetCount(&nSessionCount);
for (int n = 0; n < nSessionCount; n++)
{
IAudioSessionControl* pAudioSessionControl = NULL;
hr = pAudioSessionEnumerator->GetSession(n, &pAudioSessionControl);
if (SUCCEEDED(hr))
{
IAudioSessionControl2* pAudioSessionControl2 = NULL;
hr = pAudioSessionControl->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&pAudioSessionControl2);
if (SUCCEEDED(hr))
{
/*LPWSTR pDisplayName = NULL;
hr = pAudioSessionControl2->GetDisplayName(&pDisplayName);*/
DWORD nPID = 0;
hr = pAudioSessionControl2->GetProcessId(&nPID);
if (SUCCEEDED(hr))
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, nPID);
if (hProcess != NULL)
{
WCHAR wsImageName[MAX_PATH + 1];
DWORD nSize = MAX_PATH;
if (QueryFullProcessImageNameW(hProcess, NULL, wsImageName, &nSize))
{
if (wcsstr(wsImageName, L"msedge") != NULL)
{
ISimpleAudioVolume* pSimpleAudioVolume;
hr = pAudioSessionControl2->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&pSimpleAudioVolume);
if (SUCCEEDED(hr))
{
hr = pSimpleAudioVolume->SetMute(TRUE, NULL);
pSimpleAudioVolume->Release();
}
}
}
CloseHandle(hProcess);
}
}
pAudioSessionControl2->Release();
}
pAudioSessionControl->Release();
}
}
pAudioSessionEnumerator->Release();
}
pAudioSessionManager2->Release();
}
pDevice->Release();
}
pDeviceEnumerator->Release();
}
CoUninitialize();
}