如何在Windows中杀死背景过程并保持前景过程运行

发布于 2025-01-28 04:00:27 字数 704 浏览 4 评论 0原文

正如标题所说,我想杀死某个程序的所有背景程序,但要在Windows上保留运行的前景程序(Server 2016)。所有过程都使用相同的.exe,因此将它们分开的唯一方法是检查它们是否在后台运行。 使用任务列表我可以看到区别:

Abbildname                     PID Sitzungsname       Sitz.-Nr. Speichernutzung
========================= ======== ================ =========== ===============
BpNexT.exe                    6900 Services                   0       254.936 K
BpNexT.exe                    6164 Console                    1        63.912 K
BpNexT.exe                    6377 Services                   0       251.234 K

必须杀死第一个和最后一个过程,第二个过程应继续运行。 我试图通过服务过滤,但失败了:

taskkill /IM BPNEXT.EXE /FI "services eq Services" /T /F

如何杀死所需的过程?

詹斯

as the title says, I want to kill all backgroundprocess of a certain program, but keep the running foreground program on windows (Server 2016). All the processes are using the same .exe and therefore the only thing to separate them is to check if they are running in background or not.
Using tasklist I can see the difference:

Abbildname                     PID Sitzungsname       Sitz.-Nr. Speichernutzung
========================= ======== ================ =========== ===============
BpNexT.exe                    6900 Services                   0       254.936 K
BpNexT.exe                    6164 Console                    1        63.912 K
BpNexT.exe                    6377 Services                   0       251.234 K

The first and last process has to be killed, the second one should keep running.
I tried to filter by service, but failed:

taskkill /IM BPNEXT.EXE /FI "services eq Services" /T /F

How do I kill the desired processes?

Jens

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

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

发布评论

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

评论(1

浮生面具三千个 2025-02-04 04:00:28
FOR /f "tokens=*" %%G IN ('tasklist ^| findstr /I BPNEXT.EXE ^| findstr Services') DO (
    set /a counter=1
    FOR %%H IN (%%G) DO (
        if !counter! == 2 (
            taskkill /F /PID %%H
        )
    set /a counter=!counter!+1
    )
)
FOR /f "tokens=*" %%G IN ('tasklist ^| findstr /I BPNEXT.EXE ^| findstr Services') DO (
    set /a counter=1
    FOR %%H IN (%%G) DO (
        if !counter! == 2 (
            taskkill /F /PID %%H
        )
    set /a counter=!counter!+1
    )
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文