如何从 .BAT 文件停止进程?

发布于 2024-09-02 04:49:47 字数 39 浏览 5 评论 0原文

所以我有一个从一个bat文件开始的过程。如何阻止另一个人这样做?

So I have process I started from one bat file. How to stop it from another?

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

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

发布评论

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

评论(9

墨落成白 2024-09-09 04:49:47

要终止您知道其名称的进程,请尝试:

taskkill /IM notepad.exe

这将要求它关闭,但它可能会拒绝,提供“保存更改”等。如果您想强行终止它,请尝试:

taskkill /F /IM notepad.exe

To terminate a process you know the name of, try:

taskkill /IM notepad.exe

This will ask it to close, but it may refuse, offer to "save changes", etc. If you want to forcibly kill it, try:

taskkill /F /IM notepad.exe
初吻给了烟 2024-09-09 04:49:47

由于 TASKKILL 在 Windows 的某些 Home/basic 版本上可能不可用,因此有一些替代方案:

TSKILL processName

或者

TSKILL PID

请记住 processName 不应具有 .exe 后缀,并且长度限制为 18 个字符。

另一个选项是 WMIC

wmic Path win32_process Where "Caption Like 'MyProcess.exe'" Call Terminate

wmic 提供比 taskkill 更大的灵活性。使用 wmic Path win32_process get 您可以看到可以过滤的可用文件。

As TASKKILL might be unavailable on some Home/basic editions of windows here some alternatives:

TSKILL processName

or

TSKILL PID

Have on mind that processName should not have the .exe suffix and is limited to 18 characters.

Another option is WMIC :

wmic Path win32_process Where "Caption Like 'MyProcess.exe'" Call Terminate

wmic offer even more flexibility than taskkill .With wmic Path win32_process get you can see the available fileds you can filter.

潦草背影 2024-09-09 04:49:47

我只是想在浏览器无法打开时杀死 Chrome 的所有实例(最近的 Chrome 令人讨厌的错误)。您最终可能会得到一堆从 2 到 ? 运行的 chrome.exe 进程。
我只是做了一次干净而快速的检查,看看它是否正在运行,如果是,就杀死它。最后的暂停只是为了让我可以查看结果,这是不必要的。

@echo off
:again
taskkill /F /IM "chrome.exe"
if errorlevel=0 goto end
if errorlevel=1 goto again
:end
pause

对我来说效果很好

I just wanted to kill all instances of Chrome when the browser won't open (recent Chrome annoying bug). You can end up with a bunch of chrome.exe processes running from 2 to ?.
I just did a clean and quick check to see if it's running and kill it if it is. The pause at the end is only so I can view the results, it isn't needed.

@echo off
:again
taskkill /F /IM "chrome.exe"
if errorlevel=0 goto end
if errorlevel=1 goto again
:end
pause

it works well for me

黑白记忆 2024-09-09 04:49:47

当您从批处理文件启动一个进程时,它会作为一个单独的进程启动,并且不会提示启动它的批处理文件(因为这会同时完成运行,因此父进程 ID 等内容不会对您有帮助)。

如果您知道进程名称,并且它在所有正在运行的进程中是唯一的,则可以使用 taskkill,就像 @IVlad 在评论中建议的那样。

如果它不是独一无二的,您可能需要寻找工作。它们在终止时终止所有生成的子进程。

When you start a process from a batch file, it starts as a separate process with no hint towards the batch file that started it (since this would have finished running in the meantime, things like the parent process ID won't help you).

If you know the process name, and it is unique among all running processes, you can use taskkill, like @IVlad suggests in a comment.

If it is not unique, you might want to look into jobs. These terminate all spawned child processes when they are terminated.

趴在窗边数星星i 2024-09-09 04:49:47

taskkill /F /IM notepad.exe 这是从任务管理器终止任务的最佳方法。

taskkill /F /IM notepad.exe this is the best way to kill the task from task manager.

舟遥客 2024-09-09 04:49:47

编辑:
call runntaskkill.bat 更改为 call taskkillapp.bat,否则最终会得到相同的文件。

您可以制作两个批处理文件。一个名为 runtaskkill.bat,另一个名为 taskkillapp.bat。在文件 runtaskkill.bat 中添加以下代码:

call taskkillapp.bat [filenamehere]

对于taskkill.bat:

taskkill /f /im %1

只需确保这两个文件位于同一目录(文件夹)中即可。

Edit:
call runntaskkill.bat is changed to call taskkillapp.bat or else it will end up with the same file.

You can make two batch files. One named runtaskkill.bat and another named taskkillapp.bat. To the file runtaskkill.bat add the following code:

call taskkillapp.bat [filenamehere].

And to taskkill.bat:

taskkill /f /im %1.

Just make sure that the two files are in the same directory (folder).

心病无药医 2024-09-09 04:49:47

要仅单击文件并运行消息“按任意键继续”,

@echo off
call taskkill /f /im adb.exe /im OfficeClickToRun.exe
pause>nul
exit /b 0

请添加任意数量的进程:

/im the_process_name.提示

在某处创建.bat文件的快捷方式(您可以将其拖动到开始菜单/所有程序),转到快捷方式文件属性并添加快捷键

To just click file and run with no message "press any key to continue"

@echo off
call taskkill /f /im adb.exe /im OfficeClickToRun.exe
pause>nul
exit /b 0

add any amount of processes:

/im the_process_name.exe

TIP:

Create a shortcut of the .bat file somewhere (you can drag it to start menu/all programs) , go to the shortcut file properties and add a shortcut key ????

北陌 2024-09-09 04:49:47

以下是如何从 .bat 文件中终止一个或多个进程。

步骤 1. 打开首选文本编辑器并创建一个新文件。

步骤 2. 要终止一个进程,请使用“taskkill”命令,并使用“/im”参数指定要终止的进程的映像名称。示例:

taskkill /im examplename.exe

要“强制”终止进程,请使用“/f”参数,该参数指定强制终止进程。示例:

taskkill /f /im somecorporateprocess.exe

要终止多个进程,请使用进程名称的相应进程重复步骤 2 的第一部分。示例:

taskkill /im examplename.exe
taskkill /im examplename1.exe
taskkill /im examplename2.exe

taskkill /f /im examplename.exe
taskkill /f /im examplename1.exe
taskkill /f /im examplename2.exe

步骤 3. 使用 .bat 扩展名将文件保存到所需位置。

步骤4.单击新创建的bat文件运行它。

Here is how to kill one or more processes from a .bat file.

Step 1. Open a preferred text editor and create a new file.

step 2. To kill one process use the 'taskkill' command, with the '/im' parameter that specifies the image name of the process to be terminated. Example:

taskkill /im examplename.exe

To 'force' kill a process, use the '/f' parameter which specifies that processes be forcefully terminated. Example:

taskkill /f /im somecorporateprocess.exe

To kill more than one process you repeat the first part of step 2 with the appropriate processes for the process name. Example:

taskkill /im examplename.exe
taskkill /im examplename1.exe
taskkill /im examplename2.exe

or

taskkill /f /im examplename.exe
taskkill /f /im examplename1.exe
taskkill /f /im examplename2.exe

Step 3. Save your file to your desired location with the .bat extension.

Step 4. Click the newly created bat file to run it.

≈。彩虹 2024-09-09 04:49:47

为什么不使用 PowerShell?

Stop-Process -Name notepad

如果您在批处理文件中:

powershell -Command "Stop-Process -Name notepad"
powershell -Command "Stop-Process -Id 4232"

Why don't you use PowerShell?

Stop-Process -Name notepad

And if you are in a batch file:

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