Home > Net >  Can i use nodejs to quit another application?
Can i use nodejs to quit another application?

Time:09-05

Can i use nodejs to quit / exit a completely different application or program, for example paint.exe?

I've been trying a lot of different search queries for this and i find it strange that this question has never been asked before (it seems to me)

Thank you in advance

CodePudding user response:

Yes you can,

First you need to determine the PID of the process. Then you can kill it with process.kill(pid)

To find the PID, I would recommend this ps-list npm package. It has a psList function which lists the active processes.

import psList from 'ps-list';

async function killProcess(name) {
    const processes = await psList()
    const match = processes.find(p => p.name === name);
    if (match) process.kill(match.pid)
}

killProcess('mspaint.exe');
  • Related