windows 使用 taskkill /F 返回代码 0 杀死进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3151314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:44:38  来源:igfitidea点击:

Killing a process with taskkill /F returning code 0

windowsprocessbatch-filereturn-codetaskkill

提问by Claus

I need to kill a windows process (java.exe). I'm currently using:

我需要杀死一个 Windows 进程 (java.exe)。我目前正在使用:

taskkill.exe /F /IM java.exe

I need to use the /F option since is a critical process,but in this way I get a return code 1 instead I need a return code 0 (returned when I don't use /F for killing other not critical processes)

我需要使用 /F 选项,因为它是一个关键进程,但通过这种方式我得到一个返回代码 1 而我需要一个返回代码 0(当我不使用 /F 杀死其他非关键进程时返回)

how could I fix this problem?

我怎么能解决这个问题?

Many thanks

非常感谢

回答by Venkat

You can try with :

您可以尝试:

TASKKILL /F /IM "notepad.exe"

You can know more here. Visit this blogtoo.

您可以在此处了解更多信息。也请访问此博客

回答by Rosberg Linhares

Why don't you use PowerShell?

为什么不使用 PowerShell?

Stop-Process -Name java.exe

From the old command prompt:

从旧的命令提示符:

powershell -Command "Stop-Process -Name java.exe"

回答by LCJ

I am using following command on Windows Server 2008R2

我在 Windows Server 2008R2 上使用以下命令

Taskkill /IM B2B_Crawler_V2.exe /F

Refer Taskkilland Killing a process in Batch and reporting on success

参考TaskkillKilling a process in Batch 并报告成功

回答by Sireesh Yarlagadda

Execute this in CMD

在 CMD 中执行此操作

Get the list of open processes

获取打开的进程列表

netstat -a -o -n

And then kill the process on that port with the following command

然后使用以下命令终止该端口上的进程

taskkill /F /PID <pid>