How to get the original path of a portable Electron app?

LycaKnight picture LycaKnight · Sep 19, 2017 · Viewed 16.6k times · Source

I have an Portable Electron App (packed with: electron-builder + asar, portable build) on Windows. I try to get the application path but it returns a path within the user\temp folder rather than the actual '.exe' file

Is there any way to get the original app.exe path?

I've tried the following:

  • app.getAppPath()
  • __dirname
  • require.main.filename
  • app-root-path
  • and a few node modules

The path I'm getting from my tests:

C:\Users\xxx\AppData\Local\Temp\xxxxxx.tmp\app

the actual .exe Path (where the app launched from, and what i need):

C:\Users\XXX\Documents\test\dist

I'm just starting with Electron.

Answer

LycaKnight picture LycaKnight · Oct 9, 2017

I found a solution: Use the Environment Variable (created by Electron-Builder)

process.env.PORTABLE_EXECUTABLE_DIR

to show the real Path of the App.exe. Works only packed with Electron-Builder