kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
277 stars 45 forks source link

support for asar packaged environment in Electron #13

Closed debussy2k closed 8 years ago

debussy2k commented 8 years ago

When I use node-regedit functions in Atom Electron that packaged with asar, node-regedit functions failed. Beacuse wsf files packaged in asar file don't exist in normal file system, calling wscript with wsf file fails. If wfs files were copied in temporary folder in this case and called with that, it would be a solution. I will appreciate if you support asar situation in Electron. Thanks!

kessler commented 8 years ago

Hi @debussy2k ,

In order to help you I would ask that you create a small repository that replicates the problem.

Perhaps something with a gulp script that fires a sample electron app packaged with asar?

Thanks

Yaniv

debussy2k commented 8 years ago

I think it is fixed in Electron v0.35.3. (https://github.com/atom/electron/releases) Please see "Fix child_process.execFile not working for files in asar archive."

And you can also find details of Electron issue#3512 at https://github.com/atom/electron/issues/3512 Thanks!

kessler commented 8 years ago

Excellent, can you confirm so we can close this issue?

doesdev commented 8 years ago

@debussy2k How did you end up implementing this? I've tried keeping node_modules\regedit unpacked, but still get the same error unless I don't pack the app as asar.

doesdev commented 8 years ago

Ok, got it worked out. in case anyone else stumbles across this here's what I went with. Basically, you need to explicitly point to the unpacked module dir. Somehow I thought asar may do some magic on that one, but I was mistaken.

  let appPath = app.getAppPath()
  let isAsar = !!appPath.match(/\.asar$/)
  let basePath = path.resolve(appPath, '..', '..')
  let unpackedPath = isAsar
    ? path.resolve(basePath, 'resources', 'app.asar.unpacked')
    : path.resolve(basePath, 'resources', 'app')
  let regeditPath = path.resolve(unpackedPath, 'node_modules', 'regedit')
  let regedit = isAsar ? require(regeditPath) : require('regedit')
kessler commented 8 years ago

Thanks for sharing the solution.

LyHo86 commented 7 years ago

@doesdev has just saved my life. Thanks!

CodeWithBryan commented 7 years ago

Update for those that are still running into this problem and don't want to use the above hack, use this.

https://github.com/epsitec-sa/hazardous Simply use is like this

require ('hazardous');
const regedit = require ('regedit');