daxingxing

让程序在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添加没有效果。

 

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2022-01-14
  • 2021-11-19
  • 2022-02-25
猜你喜欢
  • 2021-12-10
  • 2021-12-23
  • 2022-01-02
  • 2021-12-10
  • 2022-01-15
相关资源
相似解决方案