VC:vista(x86)以管理员身份运行程序

简介: 方法一、(http://topic.csdn.net/u/20070303/15/457ee919-8a0b-46c4-9dd7-8606631e2108.html) 在exe的工程中找manifest 中的最后一行之前加下面的代码:进行编译就可以了, 不过这样的exe只能运行管理员权限下,如果以一般用户登录,需要输入管理员的帐号及密码才行。

方法一、(http://topic.csdn.net/u/20070303/15/457ee919-8a0b-46c4-9dd7-8606631e2108.html

在exe的工程中找manifest 中的最后一行之前加下面的代码:进行编译就可以了,

<ms_asmv3:trustInfo xmlns:ms_asmv3= "urn:schemas-microsoft-com:asm.v3 ">
<ms_asmv3:security xmlns:ms_asmv3= "urn:schemas-microsoft-com:asm.v3 ">
<requestedPrivileges>
<requestedExecutionLevel level= "requireAdministrator " uiAccess= "false "> </requestedExecutionLevel>
</requestedPrivileges>
</ms_asmv3:security>
</ms_asmv3:trustInfo>

不过这样的exe只能运行管理员权限下,如果以一般用户登录,需要输入管理员的帐号及密码才行。一般都是不设requireAdministrator,而是设其为asInvoker。

不过在有些没打补丁的XP sp2的系统上,用manifest提升权限可能导致系统重启,谨慎使用!

VC6中如下:(http://blog.csdn.net/wangyong0921/archive/2008/01/21/2057662.aspx

http://www.debugman.com/read.php?tid=325

<?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="test.exe.manifest"
type="win32"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

该代码添加到VC资源中即可, 添加方式:

添加一个“custom”资源,"resource type"填24,把资源ID改为1

如果只有一个可执行文件,也可以通过以下方法添加:

mt.exe -manifest e4nmgr.exe.manifest -outputresource:e4nmgr.exe;1

方法二、(http://topic.csdn.net/u/20070303/15/457ee919-8a0b-46c4-9dd7-8606631e2108.html

比如我把 D:\BitSpirit\BitSpirit.exe 改为管理员权限

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

新增一个字符串键值:

名称设置为“D:\BitSpirit\BitSpirit.exe”

数值数据设置为“RUNASADMIN”

目录
相关文章
|
Web App开发 安全 Windows
Win10 开启以管理员身份运行
> 你们遇到过打开程序提示**权限不足,权限错误,无法加载xxx**,尤其是用编程语言控制电脑运行。 > 或者是执行一些命令时需要以管理员权限才执行。本文介绍多种形式开启以管理员身份运行。
|
Windows 数据安全/隐私保护 安全