Kill the batch file so that its children are also killed, in Windows

I need to run exe from cmd (wrap exe so that I can provide some command line options). The problem is that just calling exe from cmd does not make the package completely transparent: if .exe freezes, killing cmd, it will not kill exe. I need him to kill exe too. Can I do this on simple Windows (from XP up) without adding any dependencies?

In Bash, you have exec , which replaces the shell process with the supplied command. This is convenient for writing shell scripts, which makes the packaging process completely transparent. I know that Windows lacks execve() to make this possible, but I'm only interested in the parent-kill-his-child part.

CLARIFICATION: I am not looking for ways to kill exe, I am looking for ways to wrap (run) exe to kill it in the usual ways (for example, Ctrl + C or from the task manager). For example, I could create an lnk file (Windows shortcut) and get this behavior, but I want to do this from a script (for one, lnks only works with absolute paths, I cannot expand it).

Thanks.

+3
source share
1 answer

Taskkill can be used to meet certain criteria. By entering Taskkill/? , you’ll get a guide and can read how to filter using common properties. I assume that all of your children have a common part on their behalf. You can use taskkill for the math name with wildcards and close all child elements matching that name.


EDIT (taken from the comments section): As Inspectable points out, you can kill all child processes using the /T flag.


EDIT, starting with a batch, you can use START ( link here ) to run exe in parallel to the batch and abort it in the package.

I wrote and tested this mini-example to edit:

 @echo off echo starting %1 start %1 echo Any key to kill execution pause >> NUL taskkill /IM %1 /t 
0
source

Source: https://habr.com/ru/post/1244454/


All Articles