Python使用Pymem无法检测Calc.exe运行状态的问题求助
问题分析与解决方案
核心原因
Windows 10及以后的默认计算器是UWP(通用Windows平台)应用,而非传统的Win32程序,它的进程名不是你查找的calc.exe——这就是为什么任务管理器“详细信息”里找不到calc.exe,Pymem自然也检测不到。
解决步骤
确认实际进程名
打开任务管理器,找到“计算器”应用,右键选择「转到详细信息」,就能看到它的真实进程名(通常是Calculator.exe,注意首字母大写)。修改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.")备选方案:通过窗口标题检测
如果担心进程名变化,也可以用窗口标题判断计算器是否运行(需安装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
相关产品推荐
相关产品推荐

