如何获取便携式 Electron 应用程序的原始路径? [英] How to get the original path of a portable Electron app?
问题描述
我在 Windows 上有一个便携式电子应用程序(包含:electron-builder + asar,便携式构建).我尝试获取应用程序路径,但它返回 user emp 文件夹中的路径,而不是实际的.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 emp folder rather than the actual '.exe' file
有什么办法可以得到原来的app.exe路径?
Is there any way to get the original app.exe path?
我尝试了以下方法:
- app.getAppPath()
- __目录名
- require.main.filename
- 应用程序根路径
- 和一些节点模块
我从测试中得到的路径:
The path I'm getting from my tests:
C:UsersxxxAppDataLocalTempxxxxxx.tmpapp
C:UsersxxxAppDataLocalTempxxxxxx.tmpapp
实际的 .exe 路径(应用程序从哪里启动,以及我需要什么):
the actual .exe Path (where the app launched from, and what i need):
C:UsersXXXDocuments estdist
C:UsersXXXDocuments estdist
我只是从 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
这篇关于如何获取便携式 Electron 应用程序的原始路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!