import ctypes
from ctypes import wintypes

user32 = ctypes.windll.user32
hwinsta = user32.OpenWindowStationW("WinSta0", False, 0x10000000)
if hwinsta:
    user32.SetProcessWindowStation(hwinsta)
hdesk = user32.OpenDesktopW("Default", 0, False, 0x10000000)
if hdesk:
    user32.SetThreadDesktop(hdesk)

print("hwinsta:", hwinsta, "hdesk:", hdesk)

def enum_cb(hwnd, lparam):
    title = ctypes.create_unicode_buffer(256)
    user32.GetWindowTextW(hwnd, title, 256)
    pid = wintypes.DWORD()
    user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
    cls = ctypes.create_unicode_buffer(256)
    user32.GetClassNameW(hwnd, cls, 256)
    if title.value or pid.value == 39484:
        if any(k in title.value.lower() for k in ['poe', 'exile', 'path', 'visual']) or pid.value == 39484:
            print(f'hwnd={hwnd} pid={pid.value} title="{title.value}" class="{cls.value}"')
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_bool, wintypes.HWND, wintypes.LPARAM)
user32.EnumDesktopWindows(hdesk, WNDENUMPROC(enum_cb), 0)
