3

I would like to list the applications displayed in the windows volume mixer.

In this example, "sons systeme", "Windows" and "spotify" enter image description here I write some code and I´m able to count and list those applications. The problem is I cant fetch their name nor their icon path Here is the output :

Session Name:
Icon path Name:
Session Name:
Icon path Name:
Session Name:
Icon path Name:
Session Name: @%SystemRoot%\System32\AudioSrv.Dll,-202
Icon path Name: @%SystemRoot%\System32\AudioSrv.Dll,-203

I don´t understand why I can´t fetch this kind of data.

Here is my code :

 IMMDevice* pDevice = NULL;
IMMDeviceEnumerator* pEnumerator = NULL;
IAudioSessionControl* pSessionControl = NULL;
IAudioSessionControl2* pSessionControl2 = NULL;
IAudioSessionManager2* pSessionManager = NULL;

hr = CoInitialize(NULL);

// Create the device enumerator.
hr = CoCreateInstance(
            __uuidof(MMDeviceEnumerator),
            NULL, CLSCTX_ALL,
            __uuidof(IMMDeviceEnumerator),
            (void**)&pEnumerator);

// Get the default audio device.
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
hr = pDevice->Activate(__uuidof(IAudioSessionManager2),
                             CLSCTX_ALL,
                             NULL, (void**)&pSessionManager);

hr = pSessionManager->GetAudioSessionControl(0, FALSE, &pSessionControl);

// Get the extended session control interface pointer.
hr = pSessionControl->QueryInterface(__uuidof(IAudioSessionControl2), (void**) &pSessionControl2);

// Check whether this is a system sound.
hr = pSessionControl2->IsSystemSoundsSession();

int cbSessionCount = 0;
LPWSTR pswSession = NULL;

IAudioSessionEnumerator* pSessionList = NULL;

hr = pSessionManager->GetSessionEnumerator(&pSessionList);
hr = pSessionList->GetCount(&cbSessionCount);
std::cout << cbSessionCount << std::endl;
for (int index = 0 ; index < cbSessionCount ; index++)
{
    hr = pSessionList->GetSession(index, &pSessionControl);
    hr = pSessionControl->GetDisplayName(&pswSession);
    std::wcout << "Session Name: " <<  pswSession << std::endl;
    hr = pSessionControl->GetIconPath(&pswSession);
    std::wcout << "Icon path Name: " <<  pswSession << std::endl;
}
Erwan Douaille
  • 550
  • 1
  • 5
  • 30

1 Answers1

-1

You can retrieve the name by using the ProcessID

DWORD procID;
pSessionControl2->GetProcessId(&procID);

And then with the ProcessID you can get a handle of the program and find the name and icon.

Zero
  • 190
  • 1
  • 3
  • 11