document.write("");

psutil 检测exe是否已经运行

安装依赖

pip install psutil

 

代码

import psutil

def check_if_process_running(process_name):
    '''
    Check if there is any running process that contains the given name process_name.
    '''
    # Iterate over the all the running process
    for proc in psutil.process_iter():
        try:
            # Check if process name contains the given name string.
            if process_name.lower() in proc.name().lower():
                return True
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    return False;

# Check if "example.exe" process is running
is_running = check_if_process_running('xxx.exe')

print('xxx.exe is running: ' + str(is_running))

  

posted @ 2024-06-11 11:18  人间春风意  阅读(6)  评论(0编辑  收藏  举报