如何获得便携式电子应用程序的原始路径? [英] How to get the original path of a portable Electron app?
问题描述
我在Windows上有一个Portable Electron App(打包:electron-builder + asar,可移植版本).我尝试获取应用程序路径,但它返回的是user \ temp文件夹中的路径,而不是实际的".exe"文件
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
有没有办法获取原始的app.exe路径?
Is there any way to get the original app.exe path?
我尝试了以下操作:
- app.getAppPath()
- __ dirname
- require.main.filename
- 应用程序根路径
- 和一些节点模块
我从测试中得到的路径:
The path I'm getting from my tests:
C:\ Users \ xxx \ AppData \ Local \ Temp \ xxxxxx.tmp \ app
C:\Users\xxx\AppData\Local\Temp\xxxxxx.tmp\app
实际的.exe路径(应用从何处启动以及我需要什么):
the actual .exe Path (where the app launched from, and what i need):
C:\ Users \ XXX \ Documents \ test \ dist
C:\Users\XXX\Documents\test\dist
我只是从Electron开始.
I'm just starting with Electron.
推荐答案
我找到了一个解决方案: 使用环境变量(由Electron-Builder创建)
I found a solution: Use the Environment Variable (created by Electron-Builder)
process.env.PORTABLE_EXECUTABLE_DIR
显示App.exe的真实路径. 仅适用于Electron-Builder
to show the real Path of the App.exe. Works only packed with Electron-Builder
这篇关于如何获得便携式电子应用程序的原始路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!