forked from ppoffice/wmic.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elevate.js
27 lines (26 loc) · 1004 Bytes
/
elevate.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
const elevate = require('sudo-prompt').exec;
const wmic = require('../lib/wmic');
const extract = wmic.extract;
const DateTime = wmic.Types.DateTime;
describe('Elevate Script Environment Test', function() {
this.timeout(0);
it('Should pop out an UAC dialog', function (done) {
function exec(command) {
return new Promise(function(resolve, reject) {
elevate(command, {
maxBuffer: 10 * 1024 * 1024
}, function(error, stdout, stderr) {
if (error) {
reject(error);
} else if (stderr.trim()) {
reject(new Error(stderr));
} else {
resolve(extract(stdout));
}
})
})
}
wmic({ exec }).alias('OS').where('Primary', true).call('SetDateTime', new DateTime(new Date(2017, 0, 1)))
.then(result => done()).catch(done)
});
});