简体   繁体   English

可执行文件是否可以要求管理员权限? (Windows 7的)

[英]Is it possible for the executable to ask for Administrator rights? (Windows 7)

I am developing a partition disk program, and for me to read the \\\\\\\\.\\\\PhysicalDrive0 I need admin rights. 我正在开发一个分区磁盘程序,对于我来说要读取\\\\\\\\.\\\\PhysicalDrive0我需要管理员权限。

I am wondering if it is possible, in the run time, for the program to gain admin rights? 我想知道程序是否有可能在运行时获得管理员权限? Is there any win api for that? 是否有任何Win API?

I want to do that because I want the program to execute with admin rights only when it is reading/writing the disk. 我要这样做是因为我希望程序仅在读/写磁盘时才能以管理员权限执行。 For security reasons, I don't want the program to execute all the time with admin rights, because someone could find a bug (stack or heap overflow for example) in some module and execute arbitrary commands as adm. 出于安全原因,我不希望程序始终以管理员权限执行,因为有人可以在某些模块中发现错误(例如堆栈或堆溢出)并以adm身份执行任意命令。

You cannot acquire elevated privileges after the process has started. 该过程开始后,您将无法获得提升的特权。 Your options are: 您的选择是:

  1. Put the part of your application that requires elevated privileges into a separate process and manifest that with requireAdministrator . 将需要提升特权的应用程序部分放入一个单独的进程中,并通过requireAdministrator
  2. Run the part of your application that requires elevated privileges as an out-of-proc COM object. 将应用程序中需要提升特权的部分作为进程外COM对象运行。

I have never seen a way to transition rights once a process has begun executing. 一旦流程开始执行,我从未见过过渡权利的方法。 The only way I know of is for the process to be created as privileged. 我知道的唯一方法是将进程创建为特权用户。

I look forward to other answers in case there is another way. 如果还有其他方法,我也期待其他答案。

(update) (更新)
The article Teach Your Apps To Play Nicely With Windows Vista User Account Control (about halfway down) confirms that admin rights can be granted only at process creation time. 文章“ 通过Windows Vista用户帐户控制教您的应用程序可以很好地播放” (大约一半)确认了只能在进程创建时授予管理员权限。

You need to embed manifest with requireAdministrator flag 您需要使用requireAdministrator标志嵌入清单

http://msdn.microsoft.com/en-us/library/bb756929.aspx http://msdn.microsoft.com/en-us/library/bb756929.aspx

Project's Propeties (Alt + Enter) -> Linker -> Manifest File -> UAC Execution level (in VS2015, in 2010 it's similar) -> requireAdministrator or highestAvailable 项目的属性(Alt + Enter) ->链接器->清单文件-> UAC执行级别(在VS2015中,在2010年类似) -> requireAdministrator或highestAvailable

Edit: Also, if it's updating program, simply make your program's name starting with Update and Windows will automatically recognize it. 编辑:此外,如果它正在更新程序,只需使程序的名称以Update开头,Windows就会自动识别它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM