如何确定“音频会话”是哪个Windows进程控制着当前进程的输出?

时间:2019-09-03 19:34:26

标签: windows audio mixer

我碰巧在这里使用Python绑定,但是我怀疑这个问题以及最终的答案不是特定于Python的。

在Windows 10上,使用Python bindings to Windows' Core Audio library,特别是通过pycaw.AudioUtilities.GetAllSessions(),我可以看到有一个名为'conhost.exe'和pid 11512的会话,通过基本的猜测/实验,我可以看到这是一个会话,该会话(a)控制我当前进程的音频,并且(b)对应于Windows 10 Volume Mixer中的“控制台窗口主机”滑块。这是我想从程序中操作的那个,pycaw提供了绑定来实现。

到目前为止,一切都很好。我的问题是,我看不到从当前进程ID向后工作的任何方式,因此,在下次启动时,我的程序可以询问“哪个进程与控制我的音频输出的会话相对应?”我天真地希望该会话pid可能出现在当前进程的祖先中,但不会:

import os, psutil

psutil.Process(os.getpid())
# prints: psutil.Process(pid=3628, name='python.exe', started='14:56:41')

psutil.Process(os.getpid()).parent()
# prints: psutil.Process(pid=16676, name='cmd.exe', started='13:00:57')

psutil.Process(os.getpid()).parent().parent()
# prints: psutil.Process(pid=1356, name='explorer.exe', started='12:21:26')

psutil.Process(os.getpid()).parent().parent().parent()
# prints nothing. It's `None`. We've reached the top.

我应该如何查询pid来控制当前进程的音频会话? (我假设会话不会总是被命名为'conhost.exe,有时我会运行pythonw.exe在没有控制台的情况下执行相同的代码。)

0 个答案:

没有答案