如何监视远程PC上的活动窗口

Pho*_*nix 8 python wmi win32gui active-window python-3.x

我可以使用该wmi模块查看网络上远程计算机上发生的进程.这是一个使用wmi监视在我自己的PC上创建和删除的进程的示例.

import wmi, multiprocessing

def create():
    while True:
        crePro = cp()
        print('Creation',crePro.Caption,crePro.ProcessId,crePro.CreationDate)


def delete():
    while True:
        delPro = dp()
        print('Deletion',delPro.Caption,delPro.ProcessId,delPro.CreationDate)


c = wmi.WMI()
cp = c.Win32_Process.watch_for("creation")
dp = c.Win32_Process.watch_for("deletion")


if __name__ == '__main__':
    createProc = multiprocessing.Process(target = create)
    deleteProc = multiprocessing.Process(target = delete)

    createProc.start()
    deleteProc.start()
Run Code Online (Sandbox Code Playgroud)

我还读过有关使用win32gui活动窗口的信息.

import win32gui
win32gui.GetForegroundWindow()
Run Code Online (Sandbox Code Playgroud)

我读过有关的存在WM_SETFOCUS和WM_ACTIVE在win32con,但我不能确定如何连接到这些流的远程PC上.

我的问题是:如何监控远程PC的活动窗口(我想使用WM_SETFOCUS或者WM_ACTIVE)

Fer*_*ves 1

要获取活动窗口,您可以执行以下操作:

from win32gui import GetWindowText, GetForegroundWindow
active_window = GetWindowText(GetForegroundWindow())
Run Code Online (Sandbox Code Playgroud)

但是,这不会在每次 active_window 更改时向您发送信号。您可以时不时地阅读此内容,看看 active_window 是否已更改。