如何在应用程序运行时C ++,windows中请求管理员权限 [英] How to ask for admin rights in application runtime C++, windows

查看:701
本文介绍了如何在应用程序运行时C ++,windows中请求管理员权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我需要在申请运行期间要求管理员权限。

我想这样做,因为我需要更改注册表。

我不想通过清单请求它,因为它要求在应用程序启动时,而不是仅在需要时。



我该怎么办?有什么功能吗?



谢谢!



我尝试过:



搜索谷歌^^

我发现了一种明显的方式,但我不想使用它(原因)。我希望这不是唯一的方法。

解决方案

对于已经执行的进程是不可能的。您只能再启动一个进程(即使这是相同的应用程序)。另一种方法是添加适当的应用程序清单,这将迫使运行时系统从一开始就请求用户进行UAC 提升确认。



对于第一种方法,请参阅: CreateProcessAsUser函数(Windows) [ ^ ]。



对于第二种(清单)方法,请参阅以下答案: C ++ - 如何使用Visual Studio 2005中的Manifest文件以Admin权限运行应用程序? [ ^ ]。



请注意,未经用户明确同意,不可能提升权限。如果可能的话,它将无视UAC的目的。请参阅:用户帐户控制 - 维基百科,免费的百科全书 [ ^ ]。



-SA

Hello

I need to ask for admin rights during runtime of my application.
I want to do so, because I need to change registry.
I don't want to ask for it via manifest, because it asks at app start, not when needed only.

How can I do it? Is there any function for that?

Thanks!

What I have tried:

Searching google ^^
I found a manifest way to do so, but I don't want to use it (reason above). I hope it is not the only way.

解决方案

It is impossible to do for the already executing process. You can only start one more process (even if this is the same application). Another approach is to add appropriate application manifest which would force the runtime system to request the user for UAC elevation confirmation from the very beginning.

For the first approach, please see: CreateProcessAsUser function (Windows)[^].

For the second (manifest) approach, please see, for example, this answer: C++ — How to run application with Admin privileges using Manifest file in Visual Studio 2005?[^].

Note that it is impossible to elevate the privileges without explicit user's consent. If it was possible, it would defeat the purpose of UAC. Please see: User Account Control — Wikipedia, the free encyclopedia[^].

—SA


这篇关于如何在应用程序运行时C ++,windows中请求管理员权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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