forked from chfuchte/TypeScript-Window-UserList
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (61 loc) · 1.91 KB
/
index.ts
File metadata and controls
70 lines (61 loc) · 1.91 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import User from './User';
import runCmd from './runCmd';
import get from 'prompt';
import path from 'path';
import fs from 'fs';
async function input(): Promise<string> {
return new Promise((res, rej) => {
try {
get.get(["name"], (err: any, result: any) => {
if (err) {
rej(err);
} else {
res(result.name);
}
});
} catch (err) {
rej(err);
}
})
}
async function Benutzernamen(domain: boolean) {
const output: any = await runCmd("net", `user ${domain ? " /domain" : ""}`);
var outputLines: string[] = output.toString().split(' ');
var users: string[] = [];
outputLines.splice(4).filter(Boolean).forEach(async (element: string) => {
users.push(element.trimStart().trimEnd());
});
users.pop();
return users
}
async function main() {
console.log("Domänen oder lokale Benutzer abfragen?");
console.log("(1) Domänenbenutzer");
console.log("(2) lokale Benutzer");
let selection = 0;
let key: any;
key = await input();
selection = key === "1" ? 0 : selection;
selection = key === "2" ? 1 : selection;
let file = path.join(__dirname, 'users.json');
const users: string[] = await Benutzernamen(selection === 0);
for (let i = 0; i < users.length; i++) {
let username = users[i];
let user = new User(username, selection === 0);
await user.parseData();
let json = {
username: user.username,
name: user.name,
class: user.class
};
if (fs.existsSync(file) === false) {
fs.writeFileSync(file, '[\n');
}
if (i == users.length - 1) {
fs.appendFileSync(file, JSON.stringify(json) + '\n]\n');
} else {
fs.appendFileSync(file, JSON.stringify(json) + ',\n');
}
}
}
main();