Home > Software engineering >  How to retrieve audio session name similar to one in Windows' built-in mixer app?
How to retrieve audio session name similar to one in Windows' built-in mixer app?

Time:09-18

I'm building a mixer app and need to get the user-friendly names for each audio session.

I tried:

  1. IAudioSessionControl::GetDisplayName() method, but it returned empty string for each session.

  2. Calling QueryFullProcessImageName() and GetModuleFileNameEx(), but they only output C:\Users\ since I have Cyrillic letters in the path. But even if they did output the full path, I assume it would end with something like ...\brave.exe (correct me if I'm wrong), which is not a user-friendly name like Brave Browser in Windows' built-in mixer.

  3. I also tried getting all process names and PIDs like this, and later match them to session process IDs, which successfully gave me names like chrome.exe or steam.exe, but they are still, again, not quite what I want:

    std::vector<std::pair<DWORD, wchar_t*>> processes;
    
        HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 entry;
        entry.dwSize = sizeof(PROCESSENTRY32);
    
        Process32First(handle, &entry);
        do {
            processes.emplace_back(entry.th32ProcessID, entry.szExeFile);
        } while (Process32Next(handle, &entry));
    
        CloseHandle(handle);
    

What I want is to retrieve names like in the built-in mixer app, ie Steam, Chrome Browser, Zoom Meetings, etc.

Is there a way to achieve this? Or does Microsoft use some kind of black magic here?

CodePudding user response:

Calling QueryFullProcessImageName() and GetModuleFileNameEx(), but they only output C:\Users\ since I have Cyrillic letters in the path.

Then you are simply not displaying the path correctly. The presence of Cyrillic characters is not a problem.

I also tried getting all process names and PIDs like this, and later match them to session process IDs, which successfully gave me names like chrome.exe or steam.exe, but they are still, again, not quite what I want

That code doesn't work properly. You are storing pointers in your std::vector that point to a single wchar_t[] buffer which is modified on each loop iteration. You should instead store std::wstring instead of wchar_t* so each path is copied.

What I want is to retrieve names like in the built-in mixer app, ie Steam, Chrome Browser, Zoom Meetings, etc.

Once you have the path to the EXE, you can use GetFileVersionInfo() and VerQueryValue() to retrieve the app's human-readable FileDescription. See Retrieve File Description for an Application using VerQueryValue.

  • Related