如何提升应用程序启动权限
来源:互联网 发布:免费留学国家知乎 编辑:程序博客网 时间:2024/05/17 09:25
1、手动提升权限
手动提升其实也很简单,用 ShellExecuteEx 函数就可以做到:
BOOL ShellExecuteEx(LPSHELLEXECUTEINFO pExecInfo);
typedef struct _SHELLEXECUTEINFO {
} SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO;
2、自动提升权限
...
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
</trustInfo>
...
<requestedExecutionLevel level="asInvoker|highestAvailable|requireAdministrator" uiAccess="true|false"/>
asInvoker:应用程序使用与主调程序一样的权限来启动。(对于标准用户程序来说,这是推荐做法) highestAvailable:应用误用与当前用户所能获得的最高权限来运行。(管理员就是管理员权限,标准用户就是标准用户的权限) requireAdministrator:应用程序必须以管理员权限来启动。 这一段是从《Windows核发编程(第五版)》上面摘抄过来的。前面说过,它只是大概说了一下,不是很具体。 我在实现的过程中,参考了微软给的步骤,http://msdn.microsoft.com/en-us/library/bb756929.aspxmanifest文件的内容:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="IsUserAdmin" type="win32"/> <description>Description of your application</description> <!-- Identify the application security requirements. --> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo></assembly>然后在资源文件中加入: #define MANIFEST_RESOURCE_ID 1MANIFEST_RESOURCE_ID RT_MANIFEST "IsUserAdmin.exe.manifest"或者在把这个.manifest文件添加到工程设置中:
Open your project in Microsoft Visual Studio 2005.
Under Project, select Properties.
In Properties, select Manifest Tool, and then select Input and Output.
Add in the name of your application manifest file under Additional manifest files.
Rebuild your application.
我几种方案都试了,但就是链接有错,什么错呢?如下: "manifest authoring error c1010001: Values of attribute 'level' not equal in different manifest snippets." 我之前一直以为是我的.manifest文件写有有错,最好在网上查了一下,不是文件写错,而是环境的问题。 以上的做法适合在VS2005下面使用。在VS2005下面使用是没有问题的。 VS2008下面这种做法就不对,因为VS2008已经能生成一个.manifest文件。而且实现提升权限功能在VS2008下面相当简单:Properties->Configuration Properties->Linker->Manifest File 按照这样的设置就行了,所以在VS2008下面实现提升权限就不需要配置.manifest文件。经过配置后,重新编译出的程序的图标上面就会有一个小盾牌,运行时就会弹出UAC对话框。如下图所示。
- 如何提升应用程序启动权限
- 如何提升应用程序启动权限
- 如何判断应用程序是以管理员身份运行,和如何判断应用程序是以提升的权限来启动的,还是正在使用筛选的令牌运行
- Vista下提升应用程序权限
- c++ 提升应用程序的权限
- c++ 提升应用程序的权限
- 如何提升进程权限
- 如何提升程序权限
- 如何绕过防火墙提升权限
- 如何使用MySQL提升权限
- 如何提升进程的权限
- 如何提升进程的权限
- 以system权限启动应用程序
- 以system权限启动应用程序
- 以system权限启动应用程序
- 应用程序如何启动autocad
- Dalvik 如何启动应用程序
- 如何利用VNC服务提升权限
- Hadoop Metrics体系分析之三:构建自己的Metrics
- RTSP基本概念
- git config 配置
- mysql-cluster 中的 sql node(主) 与 单独的 mysql server(从) 做主从复制(已解决)
- Top 命令详解
- 如何提升应用程序启动权限
- Base64Encoder源码
- SQL Server中删除重复数据的几个方法
- 应届生笔试-插入排序
- python的mysql模块使用like查询
- http 状态详解
- DWZ简介及其使用
- 分子图形软件MOL4D(7) for Windows(插图70幅)
- 【互动出版网】《算法导论:原书第3版》现在购买即可领取8元现金抵用券专题活动已经上线啦