管理员Privilegs为一个单一的方法 [英] Administrator-Privilegs for a Single Method

查看:173
本文介绍了管理员Privilegs为一个单一的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前工作的一个ApplicationLauncher / Autoupdater。
以便安装/更新的应用程序文件,我需要请求管理员权限。

Im Currently working on an ApplicationLauncher / Autoupdater. So for installing/updating an app to "Program Files", i need to request Administrator rights.

好吧,既然更新只需要如果写的东西新版本中,我试图只
请求privilegs,如果有新版本中找到。

Well, since the Updater only needs to write something if new Versions are found, i tried to only request the privilegs, if a new Version is found.

升级程序执行每次,应用程序启动之前,所以问每次为Adminrights是无解...

The updater is executed everytime, before the application launches, so asking "everytime" for Adminrights is no solution...

我搜索了很多,发现如下:

I searched a lot, and found the following:

[PrincipalPermission(SecurityAction.Demand, Role = @"Administrators")]
    private void InstallOrUpdate(AppItem appItem)

但德恩我尝试这一点,更新抛出一个SecurityException ...

but wenn i try to this, the updater throws a SecurityException...

请求主体权限失败。

我究竟做错了什么?

最好的问候,
dognose

Best regards, dognose

推荐答案

一旦它的运行,则无法提升权限的应用程序。为了请求管理员角色,就需要在可执行文件的启动时间来完成。

You cannot elevate permissions for the application once it's running. In order to request the Administrators role, it will need to be done at startup time of the executable.

您最好的选择就是让你更新或者触发一个不同的可执行与在该点提升的权限请求做 InstallOrUpdate ,或者重新运行本身(使用不同的命令行参数,潜在的)。

Your best option would be to have your updater either fire a different executable to do the InstallOrUpdate, or to re-run itself (with a different command line argument, potentially) with a request for elevated permissions at that point.

这篇关于管理员Privilegs为一个单一的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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