Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close another process from node on Windows

Tags:

node.js

How can I kill a process from node on Windows?

I'm making a updater. It needs close a windows executable (.exe) to download the updates. (The update process is download and overwrite). I read that this is possible with process.kill(pid[, signal])

But, How can I get the PID of the process if I know the name of the process?

like image 547
Giancarlo Ventura Granados Avatar asked Jun 22 '26 07:06

Giancarlo Ventura Granados


2 Answers

According to the documentation, you simply access the property.

process.kill(process.pid, 'SIGKILL');

This is a theoretical, untested, psuedo function that may help explain what I have in mind

exec('tasklist', (err, out, code) => { //tasklist is windows, but run command to get proccesses
    const id = processIdFromTaskList(processName, out); //get process id from name and parse from output of executed command
    process.kill(id, "SIGKILL"); //rekt
});
like image 158
Sterling Archer Avatar answered Jun 24 '26 19:06

Sterling Archer


Use node-windows to get pid of process you want to kill so that you can call process.kill. The library also provides an api to kill task.

like image 44
simon-p-r Avatar answered Jun 24 '26 20:06

simon-p-r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!