最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

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

Share Improve this question asked Apr 10, 2018 at 21:30 ResurgentResurgent 5552 gold badges9 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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./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./package/electron-sudo) or sudo-prompt (https://www.npmjs./package/sudo-prompt).

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论