简体   繁体   English

无法检测 Calc.exe 是否正在运行 - Python

[英]Unable to detect if Calc.exe is running - Python

I am trying to open a window application when it is not opened in the background.我试图打开一个 window 应用程序,但它没有在后台打开。 To do that, I need to check if the process is running in the background.为此,我需要检查进程是否在后台运行。 I am using pymen to check if the calc.exe is running, and if it's not, I will use subprocess to open a new calc.exe window. However, the code that I am using is not detecting if my calc.exe is actually running or not.我正在使用 pymen 检查 calc.exe 是否正在运行,如果没有,我将使用子进程打开一个新的 calc.exe window。但是,我使用的代码没有检测我的 calc.exe 是否真的在运行跑步与否。 It will always be Calculator is Not Running...它将始终是计算器未运行...

from pymem import Pymem

try:

    pm = Pymem('calc.exe')
    print('Calculator Started And Is Running....')

except:

    print ('Calculator Is Not Running....')

I believe that the code is going through the details tab as shown as below to check if calc.exe is running or not.我相信代码正在通过如下所示的详细信息选项卡来检查 calc.exe 是否正在运行。 However, I can't find it in here as well even though the calculator app is running.但是,即使计算器应用程序正在运行,我也无法在这里找到它。

The detail tab in Task Manager任务管理器中的详细信息选项卡

App like Notepad and Chrome are working fine but calculator.记事本和 Chrome 之类的应用程序运行良好,但计算器。 I have no idea why it is not working for calculator.我不知道为什么它不适用于计算器。

From Microsoft Calculator Windows 10 :来自微软计算器 Windows 10

The Calculator in non-LTSC editions of Windows 10 is a Universal Windows Platform app . Windows 10 的非 LTSC 版本中的计算器是通用 Windows 平台应用程序 In contrast, Windows 10 LTSC (which does not include universal Windows apps ) includes the traditional calculator, but which is now named win32calc.exe .相比之下,Windows 10 LTSC(不包括通用 Windows 应用程序)包含传统计算器,但现在名为win32calc.exe … Both the universal Windows app and LTSC's win32calc.exe register themselves with the system as handlers of a ' calculator: ' pseudo-protocol. ...通用 Windows 应用程序和 LTSC 的win32calc.exe将自己注册为“ calculator: ”伪协议的处理程序。 ……
All Windows 10 editions (both LTSC and non-LTSC) continue to have a calc.exe , which however is just a stub that launches (via ShellExecute ) the handler that is associated with the ' calculator: ' pseudo-protocol.所有 Windows 10 版本(LTSC 和非 LTSC)都继续有一个calc.exe ,但是它只是一个启动(通过ShellExecute )与“ calculator: ”伪协议关联的处理程序的存根

In other words, calc.exe is merely a wrapper which launches another executable:换句话说, calc.exe只是一个启动另一个可执行文件的包装器:

import psutil
import subprocess
import time


def list_calc(phase):
    print(phase)
    for proc in psutil.process_iter():
        if proc.name().startswith( PROCNAME):
            print( proc.name())
            print( proc.cmdline()[0])
            if proc.name() == 'CalculatorApp.exe':
                proc.kill()


PROCNAME = 'Calc'

list_calc('- before:')

calc = subprocess.Popen([PROCNAME+'.exe'])
time.sleep(3) # wait until calculator window appears

list_calc('- after:')

Result : ver &&.\SO\75191242.py结果ver &&.\SO\75191242.py

 Microsoft Windows [Version 10.0.19045.2486] - before: - after: CalculatorApp.exe C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_11.2210.0.0_x64__8wekyb3d8bbwe\CalculatorApp.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 PyQt 应用程序中运行 Windows 可执行文件(calc.exe 等) - Running a Windows executable (calc.exe, etc) inside a PyQt Application Python子进程kill适用于“ notepad.exe”,但不适用于“ calc.exe” - Python subprocess kill is working for “notepad.exe” but not working for “calc.exe” 尝试将调试器附加到 calc.exe 时出现系统错误代码 0x32 - System Error Code 0x32 when trying to attach debugger to calc.exe 运行 python 脚本作为 exe - running python script as exe Python 3.5.2-如何使用备用模块检测正在运行的程序,即“ chrome.exe” - Python 3.5.2 - How to detect a program running i.e “chrome.exe” using stock modules 当 python.exe 设置为“以管理员身份运行”时,在 Windows 中运行 python 脚本会给出“无法使用...创建进程” - Running a python script in Windows gives "Unable to Create Process Using ..." when python.exe set to 'run as administrator' 从python运行外部EXE - Running external EXE from python 在python中运行exe文件 - 不工作 - Running an exe file in python - not working 无法使用python调用exe - unable to call exe using python 没有这样的文件或目录,在 .net core 中运行控制台应用程序时无法在 docker 容器中找到 Python.exe - No such file or directory, Unable to find Python.exe in docker container when running console app in .net core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM