kernel32 = ctypes.windll.kernel32
SYNCHRONIZE = 1048576
process = kernel32.OpenProcess(SYNCHRONIZE, 0, pid)
if process != 0:
    kernel32.CloseHandle(process)
Check if PID exists on Windows with Python without requiring libraries