|  |  | @@ -1,4 +1,5 @@ | 
		
	
		
			
			|  |  |  | #!/usr/bin/env node | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | // 'use strict'; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere. | 
		
	
		
			
			|  |  |  | 
 | 
		
	
	
		
			
			|  |  | @@ -319,6 +320,7 @@ var __runcmd = function(label){ | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | , 'runas' : ()=>{ | 
		
	
		
			
			|  |  |  | console.log('Testing Elevation') | 
		
	
		
			
			|  |  |  | return isRunningElevated().then( | 
		
	
		
			
			|  |  |  | (isElevated) => { | 
		
	
		
			
			|  |  |  | if(isElevated)  { | 
		
	
	
		
			
			|  |  | @@ -343,34 +345,41 @@ var __runcmd = function(label){ | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 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' : ()=>{ | 
		
	
	
		
			
			|  |  | @@ -1160,9 +1169,11 @@ function nodeShellExec() { | 
		
	
		
			
			|  |  |  | if(opts.stdio !== 'ignore') { | 
		
	
		
			
			|  |  |  | child.stdout.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) => { | 
		
	
		
			
			|  |  |  | if(+code !== 0) success = false; | 
		
	
	
		
			
			|  |  | @@ -1179,7 +1190,7 @@ function nodeShellExec() { | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | if(code !== 0) return reject(code) | 
		
	
		
			
			|  |  |  | resolve(true) | 
		
	
		
			
			|  |  |  | resolve(messages) | 
		
	
		
			
			|  |  |  | }); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else { |