Is it possible for the executable to ask for Administrator rights? (Windows 7)(可执行文件是否可以要求管理员权限?(Windows 7的))
问题描述
我正在开发一个分区磁盘程序,我需要管理员权限才能读取\\.\PhysicalDrive0.
I am developing a partition disk program, and for me to read the \\.\PhysicalDrive0 I need admin rights.
我想知道程序是否有可能在运行时获得管理员权限?有没有win api?
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?
我想这样做是因为我希望程序仅在读取/写入磁盘时以管理员权限执行.出于安全原因,我不希望该程序始终以管理员权限执行,因为有人可能会在某个模块中发现错误(例如堆栈或堆溢出)并以 adm 身份执行任意命令.
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.
推荐答案
在进程开始后,您将无法获得提升的权限.您的选择是:
You cannot acquire elevated privileges after the process has started. Your options are:
- 将需要提升权限的应用程序部分放入一个单独的进程中,并使用
requireAdministrator进行说明. - 将需要提升权限的应用程序部分作为进程外 COM 对象运行.
这篇关于可执行文件是否可以要求管理员权限?(Windows 7的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:可执行文件是否可以要求管理员权限?(Windows 7的
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
