[英]How to launch an application with admin rights in c++?
I need to do some registry operations & other system operations for that i need admin permission. 我需要执行一些注册表操作和其他系统操作,这需要管理员权限。 currently user have to start my application as "Run as administrator".
当前用户必须以“以管理员身份运行”启动我的应用程序。
so How could i launch my application with admin rights? 所以我如何以管理员权限启动我的应用程序?
CreateProcessAsUser
or CreateProcessWithLogonW
is the main thing you need. CreateProcessAsUser
或CreateProcessWithLogonW
是您需要的主要内容。 For CreateProcessAsUser
, you'll need to use a few other things to make it do its tricks though (eg, AdjustTokenPrivileges
to enable the privileges it uses, and LogonUser
to get a user's token). 对于
CreateProcessAsUser
,您需要使用其他一些东西来使其发挥作用(例如, AdjustTokenPrivileges
启用它使用的特权, LogonUser
获取用户的令牌)。
You can also use ShellExecuteEx () for this purpose. 您也可以为此使用ShellExecuteEx ()。 This routine expects a SHELLEXECUTEINFO structure to be passed to it.
该例程希望将SHELLEXECUTEINFO结构传递给它。 The relevant attribute of this structure is "lpverb" which has to be set to a value "runas".
该结构的相关属性是“ lpverb”,必须将其设置为值“ runas”。 This will ensure that the task that is run with elevated priveleges.
这将确保以特权提升运行的任务。
答案涉及以编程方式启动它,但是如果程序的全部目的是以管理员身份运行以进行这些更改,则可以添加适当的清单以使Windows升级。
如果仅部分应用程序需要管理员访问权限,请查看COM标高 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.