How to get the source path of the Electron portable application?

I have a Portable Electron application (complete with: electronic builder + asar, portable assembly) on Windows. I am trying to get the path to the application, but it returns the path in the user \ temp folder, not the actual .exe file.

Is there a way to get the source path of app.exe?

I tried the following:

  • app.getAppPath ()
  • __ directory_name
  • require.main.filename
  • root path application
  • and several node modules

The path I get from my tests is:

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

actual .exe path (where the application starts from and what I need):

C: \ Users \ XXX \ Documents \ test \ distance

I am just starting with Electron.

+6
2

: ( Electron-Builder)

process.env.PORTABLE_EXECUTABLE_DIR

App.exe. Electron-Builder

+1

:

// If not already defined...
const { app } = require ('electron');
const path = require ('path');

let execPath;

execPath = path.dirname (app.getPath ('exe'));
// or
execPath = path.dirname (process.execPath);

:

// If not already defined...
const { remote } = require ('electron');
const path = require ('path');

let execPath;

execPath = path.dirname (remote.app.getPath ('exe'));
// or
execPath = path.dirname (remote.process.execPath);
+2

All Articles