You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python使用Pymem无法检测Calc.exe运行状态的问题求助

问题分析与解决方案

核心原因

Windows 10及以后的默认计算器是UWP(通用Windows平台)应用,而非传统的Win32程序,它的进程名不是你查找的calc.exe——这就是为什么任务管理器“详细信息”里找不到calc.exe,Pymem自然也检测不到。

解决步骤

  1. 确认实际进程名
    打开任务管理器,找到“计算器”应用,右键选择「转到详细信息」,就能看到它的真实进程名(通常是Calculator.exe,注意首字母大写)。

  2. 修改Pymem检测逻辑
    把代码中查找calc.exe的部分改成真实的进程名,示例代码:

    from pymem import Pymem
    import subprocess
    
    try:
        pm = Pymem("Calculator.exe")
        print("Calculator Is Running....")
    except Exception:
        subprocess.Popen("start calc", shell=True)
        print("Calculator Is Not Running.... Starting it now.")
    
  3. 备选方案:通过窗口标题检测
    如果担心进程名变化,也可以用窗口标题判断计算器是否运行(需安装pywin32库):

    import win32gui
    import subprocess
    
    def is_calculator_running():
        def callback(handle, extra):
            window_title = win32gui.GetWindowText(handle)
            if "计算器" in window_title:
                extra.append(handle)
            return True
        matched_windows = []
        win32gui.EnumWindows(callback, matched_windows)
        return len(matched_windows) > 0
    
    if not is_calculator_running():
        subprocess.Popen("start calc", shell=True)
        print("Calculator Is Not Running.... Starting it now.")
    else:
        print("Calculator Is Running....")
    

内容的提问来源于stack exchange,提问作者Zhi Hang Tan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 22:55:16