How can I get the application path of a portable Electron app on Windows?


#1

I have an Electron app that’s bundled into a portable App so that it’s a standalone ‘.app’ on Mac OS X and ‘.exe’ on Windows that requires no installation. On Mac OS X I can easily get the application path to determine where it is in the local file system when run. On Windows however every time I try to get the application path it returns a path within the tempdata folder rather than where the actual ‘.exe’ file resides. Apparently it’s unpacking the portable ‘.exe’ into the temp area to run from there?

I’ve tried using the first argument, app.getAppPath(), app.getPath(‘exe’), and window.require.main.filename but they all return the same tempdata path when the app is run from a portable bundle ‘.exe’

Is there any way to get the original path of the actual ‘.exe’ itself before it unpacks into the tempdata area?

I’m getting this:
C:\Users\userx\AppData\Local\Temp\nsbD0F4.tmp\app

but the actual .exe is launched from here at the moment:
C:\Users\userx\Documents\DreamLight_Constellation_2.1.3\dist


#2

Anybody?

I previously used LiveCode to develop cross-platform apps and packaged them into similar portable apps. In a self-contained LiveCode App on Windows the App path reported the path to the original self-contained application on the Windows’ hard drive, not a temp path like Electron does.

Here’s an older app I developed in LiveCode where it can tell where it is when launched on Mac or Windows.
http://dreamlight.com/shop/dli-snub-launcher-lightwave-3d-network-rendering/

Here’s a newer app I developed in Electron where it can tell where it is when launched on Mac but not on Windows. On Windows it only finds the temp directory where it must be temporarily unpacking to?
http://dreamlight.com/shop/dreamlight-constellation-lightwave-3d-network-render-controller/


#3

BTW: This is an app that’s packaged as a portable app using electron-builder.

So how do you get the portable app path where the app is in the filesystem from a portable app packaged with electron-builder on Windows? Using the normal methods all give me the path to the temp directory where it unpacks to run, not the original path where the portable app is located. Can it be done?


#4

I have the same problem with you


#5

Have you come up with any workaround?


#6

Can you not use the variable __dirname?


#7

I tried that first but all that returns is: ‘/src\containers’

That’s the path within the project folder to the source file. What I need is the path to the packaged portable app itself in the file system.
For example this path if I run the packaged portable app from the dist directory right after packing.
C:\Users\userx\Documents\DreamLight_Constellation_2.1.4\dist


#9

app.getAppPath() works fine on Mac OS X, but not on Windows (for a portable app).


#10

hey there,
i have the same problem.
any solutions or tipps out there?


#11

You can use this function to get the USER account which is like this C:/USERS/{username}/

function getUserHome() {
return process.env[(process.platform == ‘win32’) ? ‘USERPROFILE’ : ‘HOME’];
}

let me know if it helped it. And yes if you want to know where in windows they load the appdata then its
C:/USERS/{username}/appdata/

remember, you will get a path through this function.


#12

Thanks but that’s not really what I need. I need to know where the portable application file happens to be located, in a portable app that the user may run from wherever they want. It’s not installed to a specific directory. They drag it where they want it and run it from there. So I want to have the app know where it is located when launched.


#13

Hey,
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 and on Windows.


#14

EXCELLENT! Thanks!
I’ll give that a spin on my next update!