gpt4 book ai didi

python - 使用 Python 检查 Windows 上是否存在 PID 而无需库

转载 作者:可可西里 更新时间:2023-11-01 14:14:54 25 4
gpt4 key购买 nike

有没有一种方法可以在不需要库的情况下使用 Python 检查 Windows 上是否存在 PID?怎么办?

最佳答案

用一小杯 WINAPI 就可以解决这个问题。

def pid_running(pid):
import ctypes
kernel32 = ctypes.windll.kernel32
SYNCHRONIZE = 0x100000

process = kernel32.OpenProcess(SYNCHRONIZE, 0, pid)
if process != 0:
kernel32.CloseHandle(process)
return True
else:
return False

关于python - 使用 Python 检查 Windows 上是否存在 PID 而无需库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17620833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com