| }) | }) | ||||
| } | } | ||||
| , 'runas' : ()=>{ | , 'runas' : ()=>{ | ||||
| console.log('Testing Elevation') | |||||
| return isRunningElevated().then( | return isRunningElevated().then( | ||||
| (isElevated) => { | (isElevated) => { | ||||
| if(isElevated) { | if(isElevated) { | ||||
| } | } | ||||
| catch(e) { } //Ignore | catch(e) { } //Ignore | ||||
| // PB : TODO -- Convert all the cli args back to string. | |||||
| var namedArgs = []; | |||||
| Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) | |||||
| //console.log(' namedArgs : ' + namedArgs) | |||||
| process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | |||||
| var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | |||||
| nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | |||||
| , { | |||||
| inherit : true | |||||
| , shell: true | |||||
| , env: process.env | |||||
| , runas : 'self' | |||||
| , title : `runas` | |||||
| } | |||||
| ).then(()=>{ | |||||
| // runas returned. | |||||
| try { | |||||
| var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']'); | |||||
| runaslog.forEach((logEntry)=>{ | |||||
| logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' '))) | |||||
| }) | |||||
| } | |||||
| catch(e){ | |||||
| // Ignore nonexistent log | |||||
| console.warn('Run log error probably was not created by runas : ' + e) | |||||
| } | |||||
| // Find node path to send to hta. | |||||
| nodeShellExec('where', ['node']).then(r => { | |||||
| console.log('result : ' + r) | |||||
| // throw 'rrrrrrrrrrrrrrrrr' | |||||
| // PB : TODO -- Convert all the cli args back to string. | |||||
| var namedArgs = []; | |||||
| Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) | |||||
| //console.log(' namedArgs : ' + namedArgs) | |||||
| process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | |||||
| var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | |||||
| args.push('--nodepath='+r[r.length-1]) | |||||
| nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | |||||
| , { | |||||
| inherit : true | |||||
| , shell: true | |||||
| , env: process.env | |||||
| , runas : 'self' | |||||
| , title : `runas` | |||||
| } | |||||
| ).then(()=>{ | |||||
| // runas returned. | |||||
| try { | |||||
| var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']'); | |||||
| runaslog.forEach((logEntry)=>{ | |||||
| logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' '))) | |||||
| }) | |||||
| } | |||||
| catch(e){ | |||||
| // Ignore nonexistent log | |||||
| console.warn('Run log error probably was not created by runas : ' + e) | |||||
| } | |||||
| }) | |||||
| .catch(err => console.error('Elevation failed : ' + err)); | |||||
| }) | }) | ||||
| .catch(err => console.error('Elevation failed : ' + err)); | |||||
| }) | }) | ||||
| } | } | ||||
| , 'push' : ()=>{ | , 'push' : ()=>{ | ||||
| if(opts.stdio !== 'ignore') { | if(opts.stdio !== 'ignore') { | ||||
| child.stdout.setEncoding('utf8'); | child.stdout.setEncoding('utf8'); | ||||
| child.stderr.setEncoding('utf8'); | child.stderr.setEncoding('utf8'); | ||||
| child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); | |||||
| child.on('error', (chunk) => { success = false; messages.push(chunk); /*console.error(chunk)*/ }); | |||||
| child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); | |||||
| child.stdout.on('data', (chunk) => { chunk.trim() === '' ? null : messages.push(chunk); /* console.log('d: ' + chunk) */ }); | |||||
| child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */ } ); | |||||
| child.stderr.on('data', (chunk) => { messages.push(chunk); | |||||
| // console.error('stderr e: ' + chunk) | |||||
| }); | |||||
| } | } | ||||
| child.on('close', (code) => { | child.on('close', (code) => { | ||||
| if(+code !== 0) success = false; | if(+code !== 0) success = false; | ||||
| } | } | ||||
| } | } | ||||
| if(code !== 0) return reject(code) | if(code !== 0) return reject(code) | ||||
| resolve(true) | |||||
| resolve(messages) | |||||
| }); | }); | ||||
| } | } | ||||
| else { | else { |