If anyone is running into the issue that the batch file is not killable with .kill() or process.kill(processToKill.pid) or is starting another exe that is independent of the batch file, one solution that worked for me was to check the exe/process name I want to kill in the task manager and kill it with the (Windows) cmd command "taskkill /IM name.exe".
In code that looks like the following:
Executing the extra program (.bat, .exe, .lnk):
const systemprocess = require("child_process");
exampleVariable = systemprocess.exec("C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Accessories/Snipping Tool.lnk", (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
});
Killing the process:
systemprocess.exec(`taskkill /IM SnippingTool.exe`, (err, stdout, stderr) => {
if (err) {
throw err
}
if (stdout) {
console.log('stdout', stdout)
}
console.log('stderr', err)
});
Though if you execute another exe with spawn you should be able to kill it with varaibleNameOfChildProcess.kill(); like @Kworz answer suggests.