2

I've successfully built my electron application which appears to be working substantially fine.

I use the node module fsto access files for use in my application, which is standard affair for Electron. This works exactly as expected in the development environment, and even when I build my app with the asar in C:\Users\myApp\ I can access the files from the built electron application.

However, when I've created an installer and placed the application @ C:\Program Files(x86)\myApp\

fs.readFileSync

which previously worked fine both in the development verson and the built version when it was present in C:\Users\myApp\, now requires Run as Administrator Privileges to read files, else it will throw an error.

Any explanation?

Electron Version: 1.8.4 Platform: Windows 7

Resurgent
  • 525
  • 2
  • 9
  • 20

1 Answers1

5

I believe you may want to deploy some of your application data into your %APPDATA% i.e. C:\Users\yourusername\AppData\Roaming, or in the case of electron, can deploy your files into the userData folder using app.getPath('appData') which refers you to C:\Users\yourusername\AppData\Local\your_electron_app_name or app.getPath('userData'). https://github.com/electron/electron/blob/master/docs/api/app.md#appgetpathname

In that directory, you can change the files without elevated privileges.

If you look properties of your electron application folder in your Program Files, and go to the security tab, you will noticed that that permission settings for Users is (Read & execute, List folder contents, and Read); however, administrators, have access to Full control (modify, read & execute, list folder contents, read, and write).

However, if you really need to create/edit/delete files in your Program files or ProgramData will require elevated privileges and to get around that you may want to install the npm package electron-sudo (https://www.npmjs.com/package/electron-sudo) or sudo-prompt (https://www.npmjs.com/package/sudo-prompt).

Lawrence LCI
  • 71
  • 1
  • 4