Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor the active window on a remote PC

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)

like image 904
Phoenix Avatar asked Jun 23 '14 14:06

Phoenix


1 Answers

to get the Active window you can do this:

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

but, this isn't going to send a signal to you every time the active_window changes. You can read this from time to time and see if the active_window has changed.

like image 117
Fernando Freitas Alves Avatar answered Sep 27 '22 23:09

Fernando Freitas Alves