Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. const { any } = require('bbhverse');
  2. const fs = require('fs')
  3. var path = require('path');
  4. var cli = require('./cliverse')
  5. var nodeShellExec = cli.nodeShellExec;
  6. function elevatedRunIPCWriteMessage( target, m ) {
  7. fs.writeFileSync(target, ', ' + JSON.stringify( m ), { 'flag': 'a+' })
  8. }
  9. function toHTML(l, x, r, ol, or){
  10. ol = ol || '<div>'
  11. or = or || '</div>'
  12. l = l || '<div>'
  13. r = r || '</div>'
  14. if(Object.prototype.toString.call(x) === '[object Array]') {
  15. var ahtml = []
  16. x.forEach(xi => { ahtml.push( `${l}${xi}${r}` ) })
  17. return `${ol}${ahtml.join('')}${or}`
  18. }
  19. }
  20. var __isElevated = null;
  21. var shell_verse = {
  22. // getCommonTask is agnostic of whether we are running in an elevated shell or not. It runs in either case.
  23. init( o ){ Object.assign(this, o) }
  24. , downloadsdir : '../Downloads'
  25. , getCommonTask( taskToRun ){ return ()=>{ return shell_verse.runTask(taskToRun) }}
  26. , runTask : ( taskToRun ) => {
  27. if (__isElevated) return shell_verse.elevatedRunner( taskToRun )
  28. else return shell_verse.runNonElevated( taskToRun )
  29. }
  30. , elevatedRunner( taskToRun, inBatch ){
  31. // PB : TODO -- Should be called only when we are in an elevated shell that was already requested from an unelevated shell with a batch of tasks.
  32. try {
  33. var runlogjson = `${selectedinstance.root}/.elxr/run-${taskToRun.runtimestamp}/run.log`
  34. var __runasresult = null;
  35. return taskToRun().then((r)=>{
  36. // PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here...
  37. elevatedRunIPCWriteMessage( runlogjson, { info : taskToRun.info, success: true } )
  38. if(!inBatch) fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc.
  39. return __runasresult = r;
  40. })
  41. .catch((e) => {
  42. elevatedRunIPCWriteMessage( runlogjson, e)
  43. if(!inBatch)fs.writeFileSync('run.done', 'failure')
  44. console.error(e)
  45. })
  46. .finally(() => {
  47. // if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done')
  48. })
  49. }
  50. catch (e) {
  51. console.error('Error Invalid command : ' + e)
  52. if(!inBatch) fs.writeFileSync('run.done', 'error')
  53. }
  54. finally {
  55. }
  56. }
  57. , getElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runElevated(taskToRun) }}
  58. , getElevatedTaskInBatch : function( taskToRun ){ return ()=>{ return shell_verse.runElevatedInBatch(taskToRun) }}
  59. , runElevatedInBatch : ( taskToRun ) => {
  60. if (__isElevated) return shell_verse.elevatedRunner(taskToRun, true)
  61. else return shell_verse.requestElevation(shell_verse.elevatedRunner, taskToRun)
  62. }
  63. , runElevated : ( taskToRun ) => {
  64. // Let shell_verse decide whether to Elevate Out of Proc or In Proc
  65. // taskToRun by default is the launched command and args. Specially in windows out of proc.
  66. // taskToRun = taskToRun || (()=>{ return op[processedArgs.label || processedArgs._[0] || 'undefined'](processedArgs) })
  67. if(taskToRun.processedArgs.skipelevated) return Promise.resolve({ skipped : true });
  68. if (__isElevated) {
  69. return shell_verse.elevatedRunner(taskToRun)
  70. }
  71. else {
  72. console.log('Requesting Elevated Privileges');
  73. // requesteElevation is acutally request elevation and run. Both In Proc and Out of Proc.
  74. // Linux doesnt require elevation for most commands...
  75. return shell_verse.requestElevation(shell_verse.elevatedRunner, taskToRun)
  76. }
  77. }
  78. , runElevatedBatch( batchToRun ){
  79. // In windows we don't need to run each task. We hand over to another shell which in elevated state rebuilds the whole batch and runs.
  80. // Irrespective of the batch we just call runElevated once.
  81. if (__isElevated) {
  82. return any(batchToRun).then((r)=>{
  83. // PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here...
  84. // fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' })
  85. fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc.
  86. return __runasresult = r;
  87. })
  88. .catch((e) => {
  89. // fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' })
  90. fs.writeFileSync('run.done', 'failure')
  91. console.error(e)
  92. })
  93. // .finally(() => {
  94. // if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done')
  95. // });
  96. }
  97. else {
  98. return this.runElevated(batchToRun[0])
  99. }
  100. }
  101. , getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } }
  102. , runNonElevated : ( taskToRun ) => {
  103. // Let shell_verse decide whether to Elevate Out of Proc or In Proc
  104. if(__isElevated) {
  105. return Promise.resolve( 'Skipping regular task in elevated shell.' ) // Regular tasks unless marked as common tasks should not run in elevated shell...
  106. }
  107. else {
  108. // taskToRun by default is the launched command and args.
  109. // taskToRun = taskToRun || (()=>{ return op[processedArgs.label || processedArgs._[0] || 'undefined'](processedArgs) })
  110. return taskToRun().then(r=>{
  111. taskToRun.statuslog.statuslog(null, taskToRun.info /*repo*/ )
  112. return r;
  113. }).catch((e) => {
  114. e.info = taskToRun.info;
  115. if(taskToRun.errHandler) throw taskToRun.errHandler(e)
  116. taskToRun.statuslog.statuslog(e); //
  117. // console.error(e)
  118. throw e;
  119. }).finally(()=>{})
  120. }
  121. }
  122. , isElevated : ()=>{
  123. return acquireElevationState().then( ()=>{
  124. shell_verse.isElevated = () => {
  125. return Promise.resolve(__isElevated)
  126. }
  127. return shell_verse.isElevated()
  128. })
  129. }
  130. // , isElevationOutOfProc : ()=>{ return true }
  131. , acquireElevationState : () => {
  132. return nodeShellExec("fsutil", ["dirty", "query", "C:"], {
  133. inherit: true
  134. // , shell: true
  135. , stdio: 'ignore'
  136. , env: process.env
  137. , title: `check privileged execution mode using "fsutil dirty query C:"`
  138. }).then((exitcode) => {
  139. console.log('Elevated')
  140. __isElevated = true;
  141. shell_verse.acquireElevationState = ()=> Promise.resolve(__isElevated);
  142. shell_verse.isElevated = () => { return Promise.resolve(__isElevated)}
  143. return __isElevated
  144. }).catch((e) => {
  145. __isElevated = false;
  146. shell_verse.acquireElevationState = ()=> Promise.resolve(__isElevated);
  147. shell_verse.isElevated = () => { return Promise.resolve(__isElevated)}
  148. console.log('Not Elevated');
  149. return __isElevated
  150. })
  151. // .finally(()=>{
  152. // shell_verse.acquireElevationState = ()=> Promise.resolve(__isElevated);
  153. // shell_verse.isElevated = () => { return Promise.resolve(__isElevated)}
  154. // // return __isElevated; // Value returned from finally is not supported by node.
  155. // })
  156. }
  157. , getTaskCheckExists : cli.createTask('getTaskCheckExists', 'where')
  158. , getbash : ()=>{ return "C:\\Program Files\\Git\\bin\\sh.exe" }
  159. , createJuntionOrLink : (dirOrFile, target, opts) =>{
  160. return nodeShellExec('mklink', ['/J', dirOrFile, target], opts).catch((e) => { console.error(e) })
  161. }
  162. , removeJuncionOrLink : ( junctionOrLink )=>{
  163. return nodeShellExec('rmdir', [junctionOrLink], { inherit: true, shell: true, env: process.env })
  164. }
  165. , requestElevation(elevatedRunner, taskToRun) {
  166. // PB : TODO -- Multiple parallel request elevations should be queued into a batch and serialized as a single promise.
  167. var processedArgs = taskToRun.processedArgs, selectedinstance = taskToRun.selectedinstance , statuslog = taskToRun.statuslog
  168. // Wait for the runas to complete before we read it.
  169. try {
  170. fs.unlinkSync('run.done') // Need a unique file for aech elevated run.
  171. }
  172. catch (e) { } //Ignore
  173. // Find node path to send to hta.
  174. return nodeShellExec('where', ['node']).then(r => {
  175. var namedArgs = [];
  176. console.log('result : ' + JSON.stringify(r))
  177. Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; })
  178. // PB : TODO -- Convert all the cli args back to string.
  179. var args = [ path.normalize(`${selectedinstance.root}/.elxr/run-${taskToRun.runtimestamp}/windowselevate.hta`) ].concat(processedArgs._)
  180. namedArgs.length > 0 ? args = args.concat(namedArgs.join(' ')) : null;
  181. args.push('--runas=self');
  182. var elevatedruntimestamp = (new Date()).getTime()
  183. args.push(`--runtimestamp=${elevatedruntimestamp}`);
  184. // args.push('--nodepath=' + r.messages[r.messages.length - 1])
  185. // if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV)
  186. // if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..
  187. // console.dir(processedArgs._)
  188. // console.dir(namedArgs.join(' '))
  189. console.dir(args)
  190. // throw 'test'
  191. return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
  192. , {
  193. inherit: true
  194. , shell: true
  195. , env: taskToRun.ENV
  196. , runas: 'self'
  197. , title: `runas`
  198. }
  199. ).then(() => {
  200. // runas returned.
  201. try {
  202. // PB : TODO -- Log is comma prefixed. Needs to be proper JSON.
  203. var runlogjson = `${selectedinstance.root}/.elxr/run-${elevatedruntimestamp}/run.log`
  204. var runaslog = JSON.parse('[' + fs.readFileSync(runlogjson, { flags: 'a+' }) + ']');
  205. try { fs.unlinkSync(runlogjson) } catch(e){ } // PB : TODO -- Have a unique file for each elevated run.
  206. // console.log( "runaslog : " + runaslog.length )
  207. // Assemble elevated run results into the main run log
  208. runaslog.forEach((logEntry) => {
  209. statuslog.statuslog(logEntry.success ? null : logEntry, logEntry)
  210. logEntry.success ? (console.log(['success :' + (logEntry.result || logEntry.success)]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
  211. })
  212. }
  213. catch (e) {
  214. // We must have a runas log
  215. statuslog.statuslog(e)
  216. console.error('Run log error probably was not created by runas : ' + e)
  217. }
  218. })
  219. .catch(err => console.error('Elevation failed : ' + err));
  220. })
  221. }
  222. , launchui() {
  223. // PB : TODO -- Multiple parallel requests should be queued into a batch and serialized as a single promise.
  224. // PB : TODO -- cleanup elevated execution code from here. This is a non elevated hta.
  225. var processedArgs = this.processedArgs
  226. // Wait for the runas to complete before we read it.
  227. try {
  228. fs.unlinkSync('run.done') // Need a unique file for aech elevated run.
  229. }
  230. catch (e) { } //Ignore
  231. console.log(this.processedArgs.awaiturn)
  232. // Find node path to send to hta.
  233. return nodeShellExec('where', ['node']).then(r => {
  234. var namedArgs = [];
  235. console.log('result : ' + JSON.stringify(r))
  236. Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; })
  237. // PB : TODO -- Convert all the cli args back to string.
  238. var _args = []
  239. if(processedArgs._[0] === 'launchui' ) { _args = processedArgs._.slice(1); _args.splice(0,0, 'pull') } // Default command.
  240. else _args = processedArgs._;
  241. var args = [ path.normalize(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/windowselevate.hta`) ].concat(_args)
  242. namedArgs.length > 0 ? args = args.concat(namedArgs.join(' ')) : null;
  243. // args.push('--runas=self');
  244. var spawntimestamp = (new Date()).getTime()
  245. args.push(`--runtimestamp=${spawntimestamp}`);
  246. // args.push('--nodepath=' + r.messages[r.messages.length - 1])
  247. // if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV)
  248. // if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..
  249. // console.dir(processedArgs._)
  250. // console.dir(namedArgs.join(' '))
  251. console.dir(args)
  252. // throw 'test'
  253. return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
  254. , {
  255. inherit: true
  256. , shell: true
  257. , env: this.ENV
  258. // , runas: 'self'
  259. // , title: `runas`
  260. }
  261. ).then(() => {
  262. // runas returned.
  263. try {
  264. // PB : TODO -- Log is comma prefixed. Needs to be proper JSON.
  265. var runlogjson = `${this.selectedinstance.root}/.elxr/run-${spawntimestamp}/run.log`
  266. var runaslog = JSON.parse('[' + fs.readFileSync(runlogjson, { flags: 'a+' }) + ']');
  267. try { fs.unlinkSync(runlogjson) } catch(e){ } // PB : TODO -- Have a unique file for each elevated run.
  268. // console.log( "runaslog : " + runaslog.length )
  269. // Assemble elevated run results into the main run log
  270. runaslog.forEach((logEntry) => {
  271. this.statuslog.statuslog(logEntry.success ? null : logEntry, logEntry)
  272. logEntry.success ? (console.log(['success :' + (logEntry.result || logEntry.success)]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
  273. })
  274. }
  275. catch (e) {
  276. // We must have a runas log
  277. this.statuslog.statuslog(e)
  278. console.error('Run log error probably was not created by runas : ' + e)
  279. }
  280. })
  281. .catch(err => console.error('Elevation failed : ' + err));
  282. })
  283. }
  284. , ensureDirectoryExistence(filePath) {
  285. var dirname = path.dirname(filePath);
  286. if (fs.existsSync(dirname)) {
  287. return filePath;
  288. }
  289. this.ensureDirectoryExistence(dirname);
  290. fs.mkdirSync(dirname);
  291. return filePath;
  292. }
  293. , generateDependencies(){
  294. // PB : TODO -- Keep only the last n runs...
  295. // Currently it retains 2*n when proc needs to be relaunched in elevated mode !!!
  296. this.ensureDirectoryExistence(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/download.bat`)
  297. fs.writeFileSync(this.ensureDirectoryExistence(path.normalize(`${this.selectedinstance.root}/${this.downloadsdir}/readme.txt`)), `${this.getVersion()} Your local downloads for this instance`)
  298. // PB : TODO include and build from files... using rollup..
  299. var downloadbatch =
  300. `::**************************************************************************
  301. :Download_ <url> <File>
  302. Powershell.exe ^
  303. $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^
  304. [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^
  305. (New-Object System.Net.WebClient).DownloadFile('%1','%2')
  306. exit /b
  307. ::**************************************************************************`
  308. fs.writeFileSync(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/download.bat`, downloadbatch)
  309. var windowselevate =
  310. `
  311. <html><HTA:APPLICATION ID="windowselevate" icon="#"/>
  312. <script language="vbscript">
  313. document.title = "elxr control panel"
  314. self.ResizeTo 1024,1000
  315. Sub Window_Onload
  316. self.MoveTo (screen.availWidth - (screen.availWidth/2 + 40)),10
  317. End Sub
  318. Set objShell = CreateObject("WScript.Shell")
  319. Set objENV = objShell.Environment("Process")
  320. dim NODE_ENV
  321. NODE_ENV = objENV("NODE_ENV")
  322. </script>
  323. <script language="javascript">
  324. //WINDOWSTATE="minimize" SHOWINTASKBAR="no" SYSMENU="no" CAPTION="no"
  325. // https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/
  326. // alert(windowselevate.commandLine)
  327. var args = windowselevate.commandLine.split('"').slice(3);
  328. // alert(args)
  329. var processedArgs = { _ : [] }
  330. var namedArgs = [];
  331. namedArgs.push('--wd=' + objENV('wd'))
  332. // alert(namedArgs)
  333. for(var item in args){
  334. if(args[item].charAt(0) === '-'){
  335. namedArgs.push(args[item])
  336. var split = args[item].split('=');
  337. processedArgs[split[0].slice(2)] = split[1] || true;
  338. }
  339. else processedArgs._.push(args[item]);
  340. }
  341. var awaitrun = true;
  342. if(!processedArgs.awaitrun) {
  343. awaitrun = false;
  344. delete processedArgs.awaitrun
  345. }
  346. // args = args.forEach(function(item){ })
  347. // alert('processedArgs._ : ' + processedArgs._);
  348. // alert(processedArgs.runas);
  349. // alert(objENV('wd'))
  350. // PB : TODO -- Convert all the cli args back to string.
  351. // __filename will sure we are launhed using the same entry point.
  352. var cargs = (processedArgs.debug ? '--inspect-brk=9226' : '') + ' ${__filename.replace(/\\/g, '\\\\').replace("win_verse", "index")} ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ');
  353. var shell = new ActiveXObject('shell.application');
  354. // alert('launching node privilged. ' + processedArgs['nodepath'])
  355. // shell.ShellExecute('cmd.exe', '/k where node', '', '', 10);
  356. // shell.ShellExecute('cmd.exe', '/k notepad.exe', '', 'runas', 1);
  357. // shell.ShellExecute('cmd.exe ', '/k node ', '', 'runas', 1);
  358. // shell.ShellExecute('cmd.exe ', '/k node ' + cargs + '', '', 'runas', 1);
  359. // alert(cargs)
  360. function run(runas){ shell.ShellExecute('node', cargs, '', runas, 1); }
  361. if(!awaitrun) { run('runas') }
  362. var log = document.createElement('div');
  363. log.innerHTML='Please Wait';
  364. function l(msg){ log.innerHTML+= msg; };
  365. // log.style.color = 'blue';
  366. log.style.width = '95%';
  367. log.id = 'log';
  368. function endconsole(from){
  369. // alert('endconsole ' + from)
  370. if(fso.FileExists("run.done")) {
  371. fso.DeleteFile('run.done') // PB : TODO -- IPC through files is needed only for windows we need to do it per run...
  372. }
  373. // alert('closing window')
  374. window.close();
  375. };
  376. var timer = function(){
  377. // alert('here')
  378. l('.');
  379. if(fso.FileExists("run.done")) {
  380. endconsole('timer')
  381. }
  382. else window.setTimeout(timer, 1000);
  383. };
  384. // alert('/k node ' + cargs + '')
  385. // shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1);
  386. var fso = new ActiveXObject('Scripting.FileSystemObject');
  387. function i(html){ var e = document.createElement('div'); e.innerHTML = html; document.body.appendChild(e); };
  388. // window.onbeforeunload = function (e) {
  389. // endconsole('onbeforeunload')
  390. // };
  391. window.onload = function() {
  392. document.body.style.backgroundColor = 'black';
  393. document.body.style.fontFamily = 'arial';
  394. document.body.style.color = 'cyan';
  395. var cmds = document.createElement('div');
  396. cmds.innerHTML = '';
  397. cmds.w = function(msg){ cmds.innerHTML+= msg; };
  398. cmds.w('<Br/>Current config : ')
  399. // cmds.w('<div style="width:50%" onclick="endconsole()">X</div>' )
  400. cmds.w('<input type="button" value="Close Console" onclick="endconsole()">')
  401. cmds.w('<Br/>NODE_ENV = ' + NODE_ENV)
  402. var namedArgs = [];
  403. for(var v in processedArgs){
  404. if(v != '_' && v!== 'runtimestamp') {
  405. namedArgs.push('--' + v + '=' + processedArgs[v])
  406. }
  407. }
  408. // cmds.w('<Br/>cmd = ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ') )
  409. cmds.w('<Br/><Br/>')
  410. cmds.w('cmd = <input style="width:80%" type="text" value="' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ') + '"></input> <input type="button" value="Run" onclick="run()"></input>')
  411. cmds.w('${toHTML('<option>', Object.keys(this.cmds), '</option>', '<select>', '</select>')}');
  412. // cmds.style.color = 'blue';
  413. // processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null;
  414. document.body.appendChild(cmds);
  415. document.body.appendChild(log);
  416. // alert(fso.GetAbsolutePathName("."))
  417. window.setTimeout(timer, 3000);
  418. };
  419. </script>
  420. </html>
  421. `
  422. fs.writeFileSync(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/windowselevate.hta`, windowselevate)
  423. }
  424. , getchrome(){
  425. // Chrome install location from registry.
  426. return shell_verse.regread("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe\\").then(chromepath => {
  427. // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
  428. console.log(chromepath)
  429. return chromepath
  430. });
  431. }
  432. , regread(s){
  433. var uniquerun = (new Date()).getTime()
  434. var out = `${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/${uniquerun}-regread.out`
  435. var outescaped = out.replace(/\\/g,"\\\\")
  436. // console.log('out ::: ' + out)
  437. fs.writeFileSync(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/${uniquerun}-regread.js`,
  438. `
  439. // WScript.Echo('------------UNNAMED-----------')
  440. // WScript.Echo(WScript.Arguments.Item(0))
  441. argEnumerator = new Enumerator(WScript.Arguments.Unnamed)
  442. var args = []
  443. for(; !argEnumerator.atEnd(); argEnumerator.moveNext()){
  444. args.push('' + argEnumerator.item() + '')
  445. // WScript.Echo('-arg-' + argEnumerator.item() + '-arg-') // Value
  446. }
  447. // WScript.Echo(args[0])
  448. var objShell = WScript.createobject("wscript.shell")
  449. if(!args[0]) {
  450. WScript.Echo( '' )
  451. }
  452. else {
  453. WScript.Echo(args[0])
  454. var read = objShell.RegRead(args[0])
  455. try {
  456. var fs = new ActiveXObject('Scripting.FileSystemObject');
  457. var fh = fs.CreateTextFile('${outescaped}', true);
  458. fh.WriteLine(read);
  459. fh.Close();
  460. }
  461. catch(e){ WScript.Echo(e.message) }
  462. // WScript.Echo( read )
  463. }
  464. `
  465. )
  466. return nodeShellExec('cscript', [path.normalize(`${this.selectedinstance.root}/.elxr/run-${this.runtimestamp}/${uniquerun}-regread.js`), `${s}`])
  467. .then(read => {
  468. // console.log("REGREAD RESULT : " + read)
  469. // console.dir(read)
  470. if(read.success) {
  471. return (fs.readFileSync(out) + "").trim()
  472. }
  473. else throw 'regread failed'
  474. })
  475. }
  476. , iswin(){ return true}
  477. , islin(){ return false}
  478. }
  479. module.exports = shell_verse