TL;DR
I want to open my Electron App through a Windows Folder Shortcut (right-click on any folder and click Run In My Electron App), and get the folder path that initiated the app.
I managed to create the shortcut using windows Registry, but I can't find a way to get the path of the folder that initiated the app. (in the shortcut, "Temporary")
So in the above shortcut, the goal is to know the path of F:\ePC\Libraries\Videos\Loom\Temporary inside the electron app. (and the path should always be matching the folder that initiated the app).
A real-world working example: Just like when using WinRAR, you can right-click on a folder and click "Add to archive..." - the WinRAR app knows the path of the folder that has been right-clicked on. (Kind of like "open file with", but "open folder with").
Another real-world example that works with Electron is Visual Studio Code, you can right-click on a folder and click "Open With Code". How did they do that?
My Attempt
I tried to look over the documentation of Electron but only found a way to get the path of the EXE file, but not the folder that excecated that file using the Windows folder shortcut.
I tried also process.argv but it gives me the path of the exe file, and not the initiating folder.
Steps to reproduce the my attempt and test it yourself:
Get the repository and clone it. (It only has 3 files: index.js, index.html and package.json).
Open that folder in the command line and run
npm installExport the electron app by running
npm run package-win. this should export the exe file to[relative app path]/rlease-builds/windows-folder-electron-shortcut-win32-ia32/windows-folder-electron-shortcut.exe.To add the windows shortcut for the app: In the windows, registry create this:
HKEY_CLASSES_ROOT\Folder\shell\Run In My Electron App\command
Here's a step by step:
- 4 a. Open "Registry Editor" in Windows.
- 4 b. Head over to
HKEY_CLASSES_ROOT\Folder\shelland create a new folder called "Run In My Electron App" - 4 c. Inside the created folder, create
commandfolder. - 4 d. Double click on the default value and change it to the full path of the exe file.
(In my case the default value is: C:\Users\elron\apps\windows-folder-electron-shortcut\rlease-builds\Paste Folder Icon-win32-ia32\Paste Folder Icon.exe. Make sure that the path is YOUR path of .exe file of the exported app.)
When done with step 4, It should look something like this:
Result:
When running the app through a folder shortcut, it will give you the path of the EXE as expected, but not the path that initiated the app as shown in this screenshot:
And now you can test it.
Any help will be appreciated!


