c++windowswinapiprivacy

How can I programatically get which process is holding an open handle to my microphone?


I am writing a program that should do detection of camera/microphone use.

By leveraging the following registry key, I managed to get notified when a program is using my microphone:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone

Thus, I could retrieve the ImagePath of the process.

However, for web browsers like chrome.exe, it has a lot of processes running under the same name. I do not want to kill all of them, I want to kill the specific one that has the microphone handle open.

After some research, I managed to find how to do this manually for the camera, but it is not working for the microphone as detailed in this question: How can I find out which processes on my computer are accessing the microphone?

Another problem is, even though the registry event is telling me directly that chrome.exe is using the camera, by researching the camera handle in Process Explorer, the handle is actually held by svchost.exe.

How can I make any relation between the calling chrome.exe and the svchost.exe that is opening the camera? Is it possible?


Solution

  • In Windows, apps can open the microphone simultaneously or shared. "Exclusively" open is not forcing.

    If you use waveInOpen to open it, it's not opened exclusively. If you use IAudioCaptureClient to open it, it may be opened exclusively or in shared mode. Apps may also open audio with ASIO or another hardware-based way, so even if opened exclusively with one API, it may be opened with another api or get denied for opening for any reason.

    Either way, you don't know and you shouldn't search. Even if you would try to create an audio driver, the opener may just pick the driver it wants.