windows 标题名称中的 taskkill 窗口空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10948235/
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-09 09:34:27  来源:igfitidea点击:

taskkill window spaces in its title name

windowsbatch-filecmd

提问by DarVar

I'm trying to run taskkill on a console window that has spaces in it's title. How can I pass this window title to taskkill. I have tried the following:

我正在尝试在标题中有空格的控制台窗口上运行 taskkill。如何将此窗口标题传递给 taskkill。我尝试了以下方法:

taskkill /fi "WINDOWTITLE eq Administrator: My Window Title"

回答by c24w

I've had similar problems, but found out a little bit more.

我也遇到过类似的问题,但发现了更多。

Problem

问题

I have been trying to close a CMD window (run as administrator) which has set its own window title. So, run CMD as administrator and type:

我一直在尝试关闭设置了自己的窗口标题的 CMD 窗口(以管理员身份运行)。因此,以管理员身份运行 CMD 并键入:

title CMD with custom title

After much faffing, the following command showed me that setting the window title puts a leading space in front of the title! (No idea why.)

经过一番折腾,下面的命令告诉我设置窗口标题会在标题前放置一个前导空格!(不知道为什么。)

c:\>tasklist /V /FI "WindowTitle eq Administrator*"

Image Name  PID Session Name Session# Mem Usage Status  User Name       CPU Time Window Title
========== ==== ============ ======== ========= ======= =============== ======== =====================================
cmd.exe    4304 Console             1   2,492 K Running MACHINE\My Name  0:00:00 Administrator:  CMD with custom title
                                                                                               
(scroll )                                                                               extra space


Solution

解决方案

So to kill the process:

所以要杀死进程:

taskkill /F /FI "WindowTitle eq  Administrator:  CMD with custom title" /T
                                               
                                             bingo
  • /F- use the force.
  • /T- kill child-processes.
  • /F- 使用力量。
  • /T- 杀死子进程。

If you're banging your head in a similar fashion, I recommend using tasklistto poke around inside the process properties to make sure you're getting your filters right. This ballache brought to you by Windows 8.

如果您以类似的方式敲打您的头,我建议您使用tasklist它在流程属性内部进行检查,以确保您的过滤器正确。Windows 8 给你带来的这种痛快症。

Note:if the title contains quotation marks, just escape the nested ones:

注意:如果标题包含引号,只需转义嵌套的:

title "CMD with custom title"

taskkill /F /FI "WindowTitle eq  Administrator:  \"CMD with custom title\"" /T

回答by Shoresh

The trick is to name the cmd process and then kill it by calling the name you have given: The following is starting 6 parallel processes and you can kill any one of choice.

诀窍是命名 cmd 进程,然后通过调用您给定的名称来终止它:以下是启动 6 个并行进程,您可以选择终止任何一个进程。

start "cmd001" cmd.exe
start "cmd002" cmd.exe
start "cmd003" cmd.exe
start "cmd004" cmd.exe
start "cmd005" cmd.exe
start "cmd 006" cmd.exe

:: kill the process you want, e.g. cmd005

:: 杀死你想要的进程,例如 cmd005

taskkill /F /FI "WINDOWTITLE eq cmd005" /T

:: kill a process which has a SPACE in its name, e.g. cmd 006

:: 杀死名称中带有空格的进程,例如 cmd 006

taskkill /F /FI "WINDOWTITLE eq cmd 006" /T

回答by Emre Karata?o?lu

I guess this task run on your windows server . If the title includes "Administrator : " you can not kill the task via WindowTitle equal.

我猜这个任务在你的 Windows 服务器上运行。如果标题包含“管理员:”,则不能通过 WindowTitle 相等地终止任务。

You should use this : This is my killer.bat. SEARCH_PARAMETER = WHAT TITLE YOU WANNA KILL

你应该使用这个:这是我的killer.bat。SEARCH_PARAMETER = 你想杀死什么标题

@echo off
            for /f "tokens=2 delims=," %%a in ('
tasklist /fi "imagename eq cmd.exe" /v /fo:csv /nh 
^| findstr /r /c:".*SEARCH_PARAMETER[^,]*$" ') do taskkill /pid %%a

回答by Gank

taskkill /F /FI "WindowTitle eq Apache 8184"

taskkill /F /FI "WindowTitle eq Apache 8184"

回答by dbeasy

I was starting cmd shell windows using AutoIt and the tip about using tasklist really helped. I already tried the double spaces but AutoIt's Run() command created the cmd.exe shell in a manner that tasklist/taskkill could not see the window title.

我正在使用 AutoIt 启动 cmd shell 窗口,关于使用任务列表的提示真的很有帮助。我已经尝试了双空格,但 AutoIt 的 Run() 命令以 tasklist/taskkill 无法看到窗口标题的方式创建了 cmd.exe shell。

If I used a loop or AutoIt's WinKill()/WinClose() with the window title for the cmd prompt then AutoIt itself could close the window but my cmd prompt bat files only saw c:\windows\system32\cmd as the window title.

如果我使用循环或 AutoIt 的 WinKill()/WinClose() 和 cmd 提示的窗口标题,那么 AutoIt 本身可以关闭窗口,但我的 cmd 提示 bat 文件只看到 c:\windows\system32\cmd 作为窗口标题。

In this case I was able to use AutoIt to kill the window instead of from a batch script.

在这种情况下,我能够使用 AutoIt 来终止窗口,而不是使用批处理脚本。

回答by CONvid19

Late answer (4yo), but a good way to kill a process when you know only a part of the process name is using the oldWMIC.
Here's an example to findand killa process named "Administrator: My Window Title":

迟到的答案(4yo),但是当您只知道进程名称的一部分使用旧的WMIC.
这是一个示例findkill一个名为 的进程"Administrator: My Window Title"

WMIC PROCESS WHERE "NAME LIKE '%Administrator: My Window Title%'" CALL TERMINATE