From 95b52bff01222e0968288eac841b892d268f2539 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 13 Jan 2023 11:07:15 +0000 Subject: [PATCH] monitor: Comment about 'as this User' not actually being true Both the current `develop` code and this PR's new code share this behaviour. What the code does is look for windows/processes *in the current Windows session*, no matter if they're owned by the session user or not. Neither version will find a process, that would match, if it's running in another session, i.e. you'd need to switch to it via the windows Login screen. --- monitor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 72be530a..eaef3245 100644 --- a/monitor.py +++ b/monitor.py @@ -2035,7 +2035,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # # The first arg can't simply be `0`, and `win32con.PROCESS_TERMINATE` works handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, False, process_id) - if handle: # If OpenProcess succeeds then the app is already running as this user + if handle: + # If OpenProcess succeeds then the app is already running in this User session + # That *specifically* means "either this exact user, in this session, or another user via + # `runas`, but in this session", i.e. visible in the windows UI. + # If the process is running *in another session*, such that it's not actually visible right + # now, then this code will not find it. + # + # Checking if the process User matches that of the current session is trickier. + # There's a method using `wmi`, but it's **VERY SLOW**, so not appropriate here. hwnds.append(hwnd) return True