Created
June 28, 2023 19:37
-
-
Save janisblaus/31acf064744c4ff029cc23e5c2a0a54b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require('child_process'); | |
const desiredArgument = 'your_argument'; | |
exec(`wmic process where "CommandLine like '%%%${desiredArgument}%%%' and not CommandLine like '%%wmic%%'" get ProcessId`, (error, stdout) => { | |
if (error) { | |
console.error(`Error: ${error.message}`); | |
return; | |
} | |
const processIds = stdout.split('\r\r\n').filter(line => line.trim() !== 'ProcessId'); | |
processIds.forEach(processId => { | |
exec(`taskkill /PID ${processId} /F`, (error, stdout) => { | |
if (error) { | |
console.error(`Error killing process with ID ${processId}: ${error.message}`); | |
} else { | |
console.log(`Process with ID ${processId} terminated successfully.`); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment