index.js 755 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const arrify = require('arrify');
  3. const execa = require('execa');
  4. module.exports = async (input, options = {}) => {
  5. input = arrify(input);
  6. if (process.platform !== 'win32') {
  7. throw new Error('Windows only');
  8. }
  9. if (input.length === 0) {
  10. throw new Error('PID or image name required');
  11. }
  12. const args = [];
  13. if (options.system && options.username && options.password) {
  14. args.push('/s', options.system, '/u', options.username, '/p', options.password);
  15. }
  16. if (options.filter) {
  17. args.push('/fi', options.filter);
  18. }
  19. if (options.force) {
  20. args.push('/f');
  21. }
  22. if (options.tree) {
  23. args.push('/t');
  24. }
  25. for (const x of input) {
  26. args.push(typeof x === 'number' ? '/pid' : '/im', x);
  27. }
  28. return execa('taskkill', args);
  29. };