-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-userN-wmic-test.js
63 lines (54 loc) · 1.88 KB
/
get-userN-wmic-test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const os = require("os");
const fs = require('fs');
const { execFile } = require('child_process');
const { exec } = require('child_process');
let arrayListSoftware = new Array();
let tab = [];
let tab2 = [];
let varTabUserN, varUserN;
let str, strType = "";
let valueIdUser;
const child = execFile('wmic',['computersystem', 'get', 'username', '/format:CSV'], (error, stdout, stderr) => {
if (error) {
throw error;
}
arrayListSoftware = stdout.split("\n");
arrayListSoftware.splice(0, 2);
console.log(arrayListSoftware);
arrayListSoftware.pop();
console.log(arrayListSoftware);
for(let i in arrayListSoftware){
tab.push(arrayListSoftware[i].split(","));
}
varTabUserN = tab[0][1];
str = varTabUserN.split("\\");
strType = str.toString();
console.log(typeof strType);
console.log(varUserN);
let SearchIdUser = strType.split("\r");
SearchIdUser.splice(1,2);
console.log(SearchIdUser);
let SearchIdUserType = SearchIdUser.toString();
let FoundIdUser = SearchIdUserType.split(",");
valueIdUser = FoundIdUser.splice(1);
console.log(valueIdUser);
fs.stat('C:\\Users\\'+valueIdUser+'\\AppData\\Local\\Programs\\openssl', function(err) {
if (!err) {
console.log('file or directory exists');
}
else if (err.code === 'ENOENT') {
exec('mkdir C:\\Users\\'+valueIdUser+'\\AppData\\Local\\Programs\\openssl', (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log("Folder create with success ...");
});
}
});
exec('xcopy .\\openssl\\* /s /i /c /y C:\\Users\\'+valueIdUser+'\\AppData\\Local\\Programs\\openssl', (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log("Successfully");
});
});