Skip to content
Permalink
Browse files

Inline invisible.vbs script

Currently, `windosu-elevate.cmd` and `windosu-runas.cmd` call a separate
file named `invisible.vbs` to perform their tasks.

This approach doesn't work when running Windosu in Electron as an `asar`
package. `asar` archives are mounted as virtual directories in Electron.

More information about `asar` archives here:

https://github.com/atom/electron/blob/master/docs/tutorial/application-packaging.md

Given that the files don't really exist in the filesystem, the call to
`invisible.vbs` fails. Electron copes with this limitation by patching
certain node fs functions like `child_process.execFile` to extract the
file before executing it, but this of course is not possible from a cmd
file.

A decent workaround, given that `invisible.vbs` is a one line script, is
to inline it in the scripts is being called.

Fixes: balena-io/etcher#20
  • Loading branch information...
Juan Cruz Viotti
Juan Cruz Viotti committed Dec 14, 2015
1 parent dd0f276 commit 51c2b684ba7090a0cd641f7bbd0026ccd0b51135
Showing with 10 additions and 6 deletions.
  1. +0 −1 invisible.vbs
  2. +0 −1 lib/windosu.js
  3. +1 −2 src/windosu.latte
  4. +4 −1 windosu-elevate.cmd
  5. +5 −1 windosu-runas.cmd

This file was deleted.

@@ -19,7 +19,6 @@ module.exports.exec = function (command, options, callback) {
pipe: '"' + process.execPath + '" "' + path.join(__dirname, 'pipe.js') + '"',
input: inputName = id + '-in',
output: outputName = id + '-out',
invisible: path.join(__dirname, '..', 'invisible.vbs'),
stderr_redir: process.stdout.isTTY ? '2>&1' : '2> %ERROR%'
};
for (var n in temps)
@@ -32,7 +32,6 @@ module.exports.exec = function (command, options, callback) {
pipe: "\""+process.execPath+"\" \"" + path.join(__dirname, "pipe.js") + '"',
input: inputName = id + '-in',
output: outputName = id + '-out',
invisible: path.join(__dirname, '..', 'invisible.vbs'),
stderr_redir: ( process.stdout.isTTY
// If outputting to console, redirect stderr
@@ -125,4 +124,4 @@ function spawn(cmd, args) {
});

return d.promise;
}
}
@@ -6,6 +6,7 @@
Set _temp={{ temp }}
Set _tempfile=%_temp%SaveDrives.txt
Set _tempvbs=%_temp%getadmin.vbs
Set _tempinvisible=%_temp%invisible.vbs
Set DIR={{ dir }}
Set INPUT={{ input }}
Set OUTPUT={{ output }}
@@ -49,7 +50,9 @@ If ERRORLEVEL 1 (

:: Hide the window
IF [%1]==[] (
wscript.exe "{{ invisible }}" "cmd /C %~f0 run"
Echo CreateObject^("Wscript.Shell"^).Run "" ^& WScript.Arguments^(0^) ^& "", 0, False > %_tempinvisible%
wscript.exe %_tempinvisible% "cmd /C %~f0 run"
Del %_tempinvisible%
) else (

If exist "%_tempvbs%" ( Del "%_tempvbs%" )
@@ -8,10 +8,14 @@ Set INPUT={{ input }}
Set OUTPUT={{ output }}
Set CLI_WIDTH={{ cliWidth }}
Set PIPE={{ pipe }}
Set _temp={{ temp }}
Set _tempinvisible=%_temp%invisible.vbs

:: Hide the window
IF [%1]==[] (
wscript.exe {{ invisible }} "cmd /C %~f0 run"
Echo CreateObject^("Wscript.Shell"^).Run "" ^& WScript.Arguments^(0^) ^& "", 0, False > %_tempinvisible%
wscript.exe %_tempinvisible% "cmd /C %~f0 run"
Del %_tempinvisible%
) else (

cd /D %DIR%

0 comments on commit 51c2b68

Please sign in to comment.
You can’t perform that action at this time.