8

I'm able to view the processes taking place on a remote computer on my network by using the wmi module. This is an example using wmi to monitor the processes created and deleted on my own 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()

I've also read about using win32gui to get the active window.

import win32gui
win32gui.GetForegroundWindow()

And I've read about the existence of WM_SETFOCUS and WM_ACTIVE in win32con, but I'm not certain how to connect to these streams on a remote PC.

My question is: How do I monitor the active window of a remote PC (I suppose using either WM_SETFOCUS or WM_ACTIVE)

4

1 回答 1

1

要获得活动窗口,您可以这样做:

from win32gui import GetWindowText, GetForegroundWindow
active_window = GetWindowText(GetForegroundWindow())

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

于 2015-03-05T13:44:47.130 回答