windowselevate.hta 2.5KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <html><HTA:APPLICATION ID="windowselevate" icon="#"/>
  2. <script language="vbscript">
  3. document.title = "elxr control panel"
  4. self.ResizeTo 200,600
  5. Sub Window_Onload
  6. self.MoveTo (screen.availWidth - (document.body.clientWidth + 40)),10
  7. End Sub
  8. Set objShell = CreateObject("WScript.Shell")
  9. Set objENV = objShell.Environment("Process")
  10. dim NODE_ENV
  11. NODE_ENV = objENV("NODE_ENV")
  12. </script>
  13. <script language="javascript">
  14. //WINDOWSTATE="minimize" SHOWINTASKBAR="no" SYSMENU="no" CAPTION="no"
  15. // https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/
  16. // alert(windowselevate.commandLine)
  17. var args = windowselevate.commandLine.split('"').slice(3);
  18. // alert(args)
  19. var processedArgs = { _ : [] }
  20. var namedArgs = [];
  21. for(var item in args){
  22. if(args[item].charAt(0) === '-'){
  23. namedArgs.push(args[item])
  24. var split = args[item].split('=');
  25. processedArgs[split[0].slice(2)] = split[1] || true;
  26. }
  27. else processedArgs._.push(args[item]);
  28. }
  29. // args = args.forEach(function(item){ })
  30. // alert('processedArgs._ : ' + processedArgs._);
  31. // alert(processedArgs.runas);
  32. // PB : TODO -- Convert all the cli args back to string.
  33. var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ');
  34. // alert(cargs)
  35. var shell = new ActiveXObject('shell.application');
  36. // alert('launching node privilged. ' + processedArgs['nodepath'])
  37. // shell.ShellExecute('where', 'node', '', '', 10);
  38. shell.ShellExecute('node', cargs, '', 'runas', 1);
  39. // shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1);
  40. var fso = new ActiveXObject('Scripting.FileSystemObject');
  41. window.onload = function() {
  42. document.body.style.backgroundColor = 'black';
  43. document.body.style.fontFamily = 'arial';
  44. var log = document.createElement('div');
  45. log.innerHTML='Please Wait';
  46. function l(msg){ log.innerHTML+= msg; };
  47. log.style.color = 'blue';
  48. log.style.width = '95%';
  49. log.id = 'log';
  50. document.body.appendChild(log);
  51. l('<Br/>Current config : ')
  52. l('<Br/>NODE_ENV = ' + NODE_ENV)
  53. l('<Br/>cmd = ' + processedArgs._[0])
  54. processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null;
  55. l('<Br/><Br/>')
  56. var timer = function(){
  57. l('.');
  58. if(fso.FileExists("run.done")) close();
  59. else window.setTimeout(timer, 1000);
  60. };
  61. window.setTimeout(timer, 3000);
  62. };
  63. </script>
  64. </html>