如何在电子应用程序中获得永久许可? [英] How can I take persistent permissions in electron app?

查看:131
本文介绍了如何在电子应用程序中获得永久许可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个电子应用程序,在其中我需要扫描和更新需要root权限的文件.我知道我可以通过sudo.exec()运行这样的命令:

I am creating an electron app where I need to scan and update files which need root permission. I know I can run such commands using sudo.exec() in that way:

sudo.exec ("rm /private/var/log/fsck_hfs.log", options, (e, stdout, stderr) => {});

甚至我也可以在脚本中放置多个命令,并使用单个sudo.exec()执行它们.就我而言,命令需要在不同的时间执行,而我无法使用单个脚本来执行它们.用户一次又一次地授予权限很烦人.

And even I can put multiple commands in a script and execute them with single sudo.exec(). In my case, commands needs to be executed at different point of time and I cannot execute them with a single script. It is annoying for user to grant permissions again and again.

我试图用另一种方式来做到这一点(运行一段代码,在其中可以执行所有需要root权限的代码).为此,我在此处发布了另一个问题.但似乎不可能.

I tried to do it another way (to run a piece of code where everything that require root permission can be executed). For that, I posted another question here. But it seems that it is not possible.

现在,我想要一种使用安装应用程序时获得许可的方法(就像大多数应用程序在用户安装它们后所做的那样),并且能够在整个应用程序中使用sudo.exec()或其他方法来执行命令(最好是以及需要root权限的代码fs.readdir等).

Now I want a way to get permission once when use install app (as most of the apps does after user install them) and be able to use throughout the app sudo.exec() or some other method to execute commands (preferably also the code fs.readdir, etc) that require root permission.

推荐答案

您需要以管理员权限运行applicaton. 如果您使用电子生成器来构建应用,请使用 requestedExecutionLevel 值作为"requireAdministrator"

You need to run the applicaton with administrator privilege. If you are using electron builder to build the app, use the requestedExecutionLevel value as "requireAdministrator"

https://www.electron.build/configuration/win

这篇关于如何在电子应用程序中获得永久许可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆