python中如何结束另一个程序的任务?

发布于 2025-01-11 03:22:26 字数 88 浏览 4 评论 0原文

当您转到任务管理器并选择一个应用程序并按“结束任务”时,该程序将关闭。 我怎样才能在Python中完成这个过程?例如,当代码运行时,Chrome 应用程序将关闭。

When you go to Task Manager and select an app and press "End Task", the program closes.
How can I do this process in python? So when the code runs, for example, the Chrome app closes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埋葬我深情 2025-01-18 03:22:26

No.6278847 的克隆:是吗可以从 Python 中终止 Windows 上的进程吗?

您可以通过以下代码来做到这一点:

import os

def terminate(ProcessName):
    os.system('taskkill /im ' + ProcessName)

terminate('chrome.exe')

鸣谢:Nix

Clone of No.6278847: Is it possible to kill a process on Windows from within Python?

You can do that through the following code:

import os

def terminate(ProcessName):
    os.system('taskkill /im ' + ProcessName)

terminate('chrome.exe')

Credits: Nix

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文