如何在电子应用程序中获取持久权限?

How can I take persistent permissions in electron app?(如何在电子应用程序中获取持久权限?)
本文介绍了如何在电子应用程序中获取持久权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在创建一个电子应用程序,我需要在其中扫描和更新需要 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.

推荐答案

您需要以管理员权限运行应用程序.如果您使用 electron builder 构建应用程序,请使用 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

这篇关于如何在电子应用程序中获取持久权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)