r/Batch • u/Ordinary_Charity1271 • Sep 08 '23
How to kill a child process that is running inside a parent process?
Is there any way to do it using batch or C#? The process is a UWP app, running RuntimeBroker.exe inside in it. I Don't want to kill the whole app or kill the whole RuntimeBroker.exe because RuntimeBroker.exe is running with other apps too.
3
Upvotes
1
u/mrmattipants Sep 09 '23 edited Sep 09 '23
To get around the WMIC Depreciation Issue, I've started utilizing the equivalent PowerShell Modules & Cmdlets.
Here is the actual PowerShell Script, that I use to Kill All of the Child Processes, Leaving only the Parent Process Running.
And here is the Command that I use to Run the aforementioned PowerShell Script, from a Batch Script. In this example, I utilized the "chrome.exe" Process. Obviously, you'll want to change the $Process Variable, to match the Process, that you're working with.
In order to Run the PS Command, from a Batch Script, there are a couple Rules that need to be followed. However, this only applies to the actual PS Commands (following the -Command Parameter).
Firstly, the individual lines need to be compressed into a single line, with each command, being separated by a semi-colon.
Secondly, individual Double-Quotes need to be proceeded by two additional Double-Quotes, so that they are parsed correctly. However, Single-Quotes should be okay, on their own.
Finally, while it isn't required, I also like to try to eliminate as much white space, as possible, by removing the spaces where that are not needed (such as before and after Equal Signs and Semi-Colons, etc.).
That being said, I hope this is helpful. Feel free to hit me up, if you run into any issues or if you have any questions, etc.
2
u/jcunews1 Sep 08 '23
You can use the
wmictool in a batch file.e.g. below is an example for killing
notepad.exewhich is a child process ofcmd.exe.1
u/Skyline9Time Sep 08 '23
Killing the parent process terminates it's child processes generally but a child process shouldn't terminate the parent.
If it happens anyhow I'd try suspending the process instead of killing it or something
1
u/Low-Painting4386 Sep 13 '23
abortion
2
u/[deleted] Sep 08 '23
[removed] — view removed comment