Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Strange behaviour with Electron 9 on Win10 #132

Open
jdexyz opened this issue Nov 12, 2020 · 1 comment
Open

Strange behaviour with Electron 9 on Win10 #132

jdexyz opened this issue Nov 12, 2020 · 1 comment

Comments

@jdexyz
Copy link

jdexyz commented Nov 12, 2020

It seems that Electron v9 on Windows (tested on Win10) replaces child_process.exec with a promisified version of it. I could not find a reference to this behaviour in the electron repo.

This causes an error in function WindowsElevate, specifically with child.stdin.end();, as child is now a promise, and not a ChildProcess.

My temporary solution is to use child_process.execSync, which is not promisified.
Maybe this is all due to my setup, but I just thought I would report this, in case somebody else is experiencing the issue.

I am not sure this deserves a PR, so here is my replacement function :

function  WindowsElevate(instance, end) {
  // We used to use this for executing elevate.vbs:
  // var command = 'cscript.exe //NoLogo "' + instance.pathElevate + '"';
  var command = [];
  command.push('powershell.exe');
  command.push('Start-Process');
  command.push('-FilePath');
  // Escape characters for cmd using double quotes:
  // Escape characters for PowerShell using single quotes:
  // Escape single quotes for PowerShell using backtick:
  // See: https://ss64.com/ps/syntax-esc.html
  command.push('"\'' + instance.pathExecute.replace(/'/g, "`'") + '\'"');
  command.push('-WindowStyle hidden');
  command.push('-Verb runAs');
  command = command.join(' ');
  console.log('command', command)
  try{
    // Using execSync instead of exec because of an Electron bug where exec is promisified 
    // (cannot find a reference in electron repo)
    require('child_process').execSync(command, { encoding: 'utf-8' });
    end();
  }
  catch(e){
    console.error(e)
    end(new Error(PERMISSION_DENIED), "", e);
  }
}
@jorangreef
Copy link
Owner

Thanks for posting this @jeremypatrickdahan

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants