[英]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'swin32calc.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 acalc.exe
, which however is just a stub that launches (viaShellExecute
) 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.