27 lines
953 B
Python
27 lines
953 B
Python
"""List all windows (visible or not) belonging to Weixin processes."""
|
|
import win32gui, win32process, psutil, json, sys
|
|
|
|
target_pids = {}
|
|
for p in psutil.process_iter(['pid', 'name']):
|
|
try:
|
|
if p.info['name'] and p.info['name'].lower() in ('weixin.exe', 'wechat.exe'):
|
|
target_pids[p.info['pid']] = p.info['name']
|
|
except Exception:
|
|
pass
|
|
|
|
rows = []
|
|
def cb(hwnd, _):
|
|
_, pid = win32process.GetWindowThreadProcessId(hwnd)
|
|
if pid in target_pids:
|
|
rows.append(dict(hwnd=hwnd, pid=pid, cls=win32gui.GetClassName(hwnd),
|
|
title=win32gui.GetWindowText(hwnd),
|
|
visible=bool(win32gui.IsWindowVisible(hwnd)),
|
|
iconic=bool(win32gui.IsIconic(hwnd)),
|
|
rect=win32gui.GetWindowRect(hwnd)))
|
|
return True
|
|
|
|
win32gui.EnumWindows(cb, None)
|
|
print("pids:", target_pids)
|
|
for r in rows:
|
|
print(json.dumps(r, ensure_ascii=False))
|