import sys, time, ctypes, psutil
sys.stdout.reconfigure(encoding='utf-8')

user32 = ctypes.windll.user32
shell32 = ctypes.windll.shell32
hdesk = user32.OpenInputDesktop(0, False, 0x01FF)
if hdesk: user32.SetThreadDesktop(hdesk)

existing_pids = set(psutil.pids())

print("Launching Game.exe with 'runas'...")
res = shell32.ShellExecuteW(
    None,
    "runas",
    r"C:\JXVCTK\JxVoCongTruyenKy\Game.exe",
    None,
    r"C:\JXVCTK\JxVoCongTruyenKy",
    1
)
print(f"ShellExecuteW returned: {res}")

new_procs = []
start_t = time.time()
while time.time() - start_t < 12:
    time.sleep(0.5)
    current_pids = set(psutil.pids())
    diff = current_pids - existing_pids
    for pid in diff:
        if pid not in [p['pid'] for p in new_procs]:
            try:
                p = psutil.Process(pid)
                new_procs.append({'pid': pid, 'name': p.name(), 'exe': p.exe(), 'cmdline': p.cmdline()})
                print(f"[{time.time()-start_t:.1f}s] NEW PROCESS: PID {pid}, Name: {p.name()}, Cmd: {p.cmdline()}")
            except Exception as e:
                new_procs.append({'pid': pid, 'err': str(e)})

print(f"Total new processes detected: {len(new_procs)}")
for p in new_procs:
    print(" ", p)
