让程序在win7下运行时弹出"以管理员身份运行"

1.工程属性要是静态链接模式

2.资源文件中加入:

/////
//
// 24
//

124"res\\win7admin.manifest"

其中文件win7admin.manifest的内容为:

<?xml   version="1.0"   encoding="UTF-8"   standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'/>
</dependentAssembly>
</dependency>

<assemblyIdentity
processorArchitecture="x86"
version
="5.1.0.0"
type
="win32"
name
="MyApplication"
/>
<description> My Application </description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name
="Microsoft.Windows.Common-Controls"
version
="6.0.0.0"
publicKeyToken
="6595b64144ccf1df"
language
="*"
processorArchitecture
="x86"
/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>

</assembly>

 

3.工程中添加文件"res\\win7admin.manifest"

 

 如果其他程序调的,可以试试ShellExecuteEx runas

参考:http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx

 

 

在VS2010中,打开工程属性:链接器-清单文件-UAC执行级别,修改为requireAdministrator (/level='requireAdministrator')

也可以实现。

 

注意:只针对主exe有效,dll添加没有效果。

 

转载于:https://www.cnblogs.com/daxingxing/archive/2011/08/30/2159703.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值