TaskKill 用于终止 .NET 控制台应用程序

发布于 2024-09-09 04:11:59 字数 542 浏览 2 评论 0原文

我有一堆托管 WCF 服务的控制台主机应用程序。我调用 .bat 文件作为预构建步骤来终止任何正在运行的主机实例,这样我就不会收到 WCF 通道注册错误(每次在构建之前手动终止控制台主机是一件非常痛苦的事情)。

我创建的 .bat 文件包含以下内容。

taskkill /T /F /FI "imagename eq Host.vshost.exe"
taskkill /T /F /FI "imagename eq Host.exe"
exit /B 0

这会杀死两个进程。我可以在任务管理器中看到 Host.exe 消失了,Host.vshost.exe 有一个新的 PID,但控制台窗口仍然存在。 看来 cmd.exe 是托管控制台的实际进程,所以我将 .bat 文件更改为这个。

taskkill /T /F /FI "imagename eq cmd.exe"

但这会杀死所有 cmd.exe 窗口。

我如何调整这个,以便我可以仅针对特定控制台应用程序的cmd窗口,或者我应该使用不同的命令?

I have a bunch of console host applications hosting WCF services. I'm calling a .bat file as a pre build step to kill any running host instances so that I don't get WCF channel registrations errors(manually killing the console hosts each time before a build is a royal pain).

The .bat file I've created contains the following.

taskkill /T /F /FI "imagename eq Host.vshost.exe"
taskkill /T /F /FI "imagename eq Host.exe"
exit /B 0

This kills both processes. I can see in taskmanager that Host.exe is gone and Host.vshost.exe has a new PID but the Console Window is still up.
It seems that cmd.exe is the actual process hosting the console so I then changed the .bat file to this..

taskkill /T /F /FI "imagename eq cmd.exe"

But this kills all cmd.exe windows.

How can I tweak this so that i can target just the specific Console application's cmd window or is there a different command I should be using?

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

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

发布评论

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

评论(1

薯片软お妹 2024-09-16 04:11:59

taskkill 有几个选项可以帮助您缩小要终止的进程的范围。例如,您要杀死的 CMD.EXE 进程的窗口标题是否唯一(例如“批处理”而不是默认的“C:\WINDOWS\System32\cmd.exe”)?然后使用

taskkill /F /T /FI "WINDOWTITLE eq Batch Processing"

如果您需要更改目标窗口的标题,您可以使用命令 TITLE Your Title Here 从目标批处理文件中执行此操作,或者通过使用 start " 启动该过程您的标题在这里”... 命令。

taskkill has several options to help you narrow down the process you want to kill. For example, is the window title of the CMD.EXE process you want to kill unique (e.g. "Batch Processing" instead of the default "C:\WINDOWS\System32\cmd.exe")? Then use

taskkill /F /T /FI "WINDOWTITLE eq Batch Processing"

If you need to change the title of the target window, you can do so from the target batch file with the command TITLE Your Title Here, or by starting that process with a start "Your Title Here" ... command.

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