-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
46 lines (34 loc) · 995 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import process from 'node:process';
import {execa, execaSync} from 'execa';
function parseArgs(input, options) {
if (process.platform !== 'win32') {
throw new Error('Windows only');
}
input = [input].flat();
if (input.length === 0) {
throw new Error('PID or image name required');
}
const arguments_ = [];
if (options.system && options.username && options.password) {
arguments_.push('/s', options.system, '/u', options.username, '/p', options.password);
}
if (options.filter) {
arguments_.push('/fi', options.filter);
}
if (options.force) {
arguments_.push('/f');
}
if (options.tree) {
arguments_.push('/t');
}
for (const element of input) {
arguments_.push(typeof element === 'number' ? '/pid' : '/im', element);
}
return arguments_;
}
export async function taskkill(input, options = {}) {
await execa('taskkill', parseArgs(input, options));
}
export function taskkillSync(input, options = {}) {
execaSync('taskkill', parseArgs(input, options));
}