如何让程序在win7下获得管理员权限

来源:互联网 发布:年度网络安全检查报告 编辑:程序博客网 时间:2024/06/05 17:06

VS2010编写的程序可以运行时获取管理员权限;

但是如果是VS2010以前的程序呢?

方法1:移植到VS2010上了;

方法2::

(1)按照《VS2010与Win7共舞:UAC与数据重定向》上述方法,随便写一个VS2010工程,编译,在这个工程的Debug目录下会有两个文件:   *.exe.embed.manifest 和 *.exe.intermediate.manifest ;

(2)随便复制一个 .manifest 文件到你现在的工程目录的资源文件夹(res)下,然后在工程的资源中Import这个文件;

(3)资源文件夹设置为“24”,资源ID设置为“1”;

 

现在ok了,你编译的程序,可以获取管理员权限了。

 

此外还可以通过

建立文本文件, 命名为”可执行文件名.exe.manifest”,并加入以下代码:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentityversion="1.0.0.0" processorArchitecture="X86" name="VistaLogoDemo" type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements.-->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevellevel="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

运行级别有3种,这里使用 requireAdministrator 表示以管理员权限运行,如果写为 aslnvoker,那么就是以普通权限运行。

将该文件存放运行文件目录下

在VS中加载程序EXE

添加资源导入manifest文件命名为RT_MANIFEST,将其ID改为1

保存exe。

这样在V或7下就会有盾牌标志,程序启动会提示UAC而管理员权限启动

 

原创粉丝点击