使用Python检查Windows上是否存在PID而不需要库 [英] Check if PID exists on Windows with Python without requiring libraries

查看:27
本文介绍了使用Python检查Windows上是否存在PID而不需要库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不需要库的情况下使用 Python 来检查 Windows 上是否存在 PID?怎么做?

Is there a way to check if a PID exists on Windows with Python without requiring libraries? How to?

推荐答案

这可以用一点 WINAPI 解决.

This is solved with a little cup of 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检查Windows上是否存在PID而不需要库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆