electron - node.js - fs.readFileSync requires admin privileges when electron is built and in Program Files

五迷三道 提交于 2020-01-14 03:03:09

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/49763146/electron-node-js-fs-readfilesync-requires-admin-privileges-when-electron-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!