简体   繁体   English

使用 python 在任务管理器中运行同一应用程序进程的 Taskkill 多个实例

[英]Taskkill multiple instances of same application process running in task manager with python

If there are multiple instances of notepad.exe running in task manager, taskkill should kill the exe with python.如果任务管理器中有多个 notepad.exe 实例运行,taskkill 应该使用 python 终止该 exe。 If only one notepad.exe process is present then taskkill must not be done.如果只存在一个 notepad.exe 进程,则不得执行 taskkill。
How can I do this?我怎样才能做到这一点?

import os
os.system("taskkill /im notepad.exe")

As you seem to launch OS commands, using os.system() , you might consider launching this command:当您似乎使用os.system()启动操作系统命令时,您可能会考虑启动此命令:

tasklist /FI "imagename eq notepad.exe"

If the result contains only one result, do nothing.如果结果只包含一个结果,则什么也不做。 Else, kill them.否则,杀了他们。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM