import ctypes
import sys
from ctypes import wintypes
import psutil
import win32gui
import win32process

sys.stdout.reconfigure(encoding='utf-8')
user32 = ctypes.windll.user32
hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk:
    user32.SetThreadDesktop(hdesk)

windows = []
def enum_cb(h, _):
    if user32.IsWindowVisible(h):
        txt_len = user32.GetWindowTextLengthW(h) + 1
        txt_buf = ctypes.create_unicode_buffer(txt_len)
        user32.GetWindowTextW(h, txt_buf, txt_len)
        title = txt_buf.value
        
        cls_buf = ctypes.create_unicode_buffer(256)
        user32.GetClassNameW(h, cls_buf, 256)
        cls_name = cls_buf.value
        
        pid = wintypes.DWORD()
        user32.GetWindowThreadProcessId(h, ctypes.byref(pid))
        
        if any(w in title.lower() for w in ['voco', 'vlbs', 'auto', 'jx']) or any(w in cls_name.lower() for w in ['vlbs', 'voco']):
            windows.append((h, pid.value, cls_name, title))
    return True

WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
user32.EnumWindows(WNDENUMPROC(enum_cb), 0)

print(f"Found {len(windows)} candidate windows:")
for h, pid, cls_name, title in windows:
    try:
        proc = psutil.Process(pid)
        print(f"HWND: {hex(h)} | PID: {pid} | Exe: {proc.name()} | Path: {proc.exe()} | Title: '{title}' | Class: '{cls_name}'")
        print(f"   Cmdline: {proc.cmdline()}")
        print(f"   Cwd: {proc.cwd()}")
    except Exception as e:
        print(f"HWND: {hex(h)} | PID: {pid} | Title: '{title}' | Error: {e}")
