0

我正在尝试获取 Windows 中打开的应用程序列表,但最终使用

tasklist

我想获取打开的应用程序列表(不是所有进程)及其进程 ID。

例如:如果正在进行文件复制,那么我想知道它的进程 ID,类似地,如果 Chrome 中正在下载某些内容,那么我想知道该下载窗口的进程 ID。

我在 Python 中执行此操作,因此解决方案可以是与 Python 或命令提示符相关的任何内容。

4

1 回答 1

3

如果您想要流程,请参考这篇文章@Nick Perkins 和 @hb2pencil 提供了一个非常好的解决方案。

要获得所有打开的应用程序标题,您可以使用下面的代码,我也在我的一个驱动程序中使用它,它来自这个站点

这里还有另一个类似问题的帖子,@nymk 给出了解决方案。

import ctypes

EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int),     ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible

def foreach_window(hwnd, lParam):

    titles = []

    if IsWindowVisible(hwnd):
        length = GetWindowTextLength(hwnd)
        buff = ctypes.create_unicode_buffer(length + 1)
        GetWindowText(hwnd, buff, length + 1)
        titles.append(buff.value)
        print buff.value

    return titles


def main():

    EnumWindows(EnumWindowsProc(foreach_window), 0)

   #end of main
if __name__ == "__main__":
    main()
于 2013-10-12T16:57:56.067 回答