加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

VC程序执行时自动请求以管理员权限执行

(2019-01-11 15:56:51)
标签:

vc程序以管理员权限

分类: 代码天地

一  VS 2005以后,通过VS项目属性进行设置


主要转自这里 

1 中文版本

项目属性-链接器-清单文件-UAC执行级别-requireAdministrator (/level='requireAdministrator')

2 英文版本

Property-Linker-Manifest File-UAC Execution Level-requireAdministrator (/level='requireAdministrator')

VC程序执行时自动请求以管理员权限执行

3 资源文件 (.manifest文件),文件中的 name 值为,程序名称.exe,主要内容如下:

< ?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="XXX.exe" type="win32"/>
< trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
< security>
< requestedPrivileges>
< requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
< /requestedPrivileges>
< /security>
< /trustInfo>
< asmv3:application>
< asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
< ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false
< /asmv3:windowsSettings>
< /asmv3:application>
< compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
< application>
< !-- Windows 10 -->
< supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
< !-- Windows 8.1 -->
< supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
< !-- Windows Vista -->
< supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
< !-- Windows 7 -->
< supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
< !-- Windows 8 -->
< supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
< /application>
< /compatibility>
< /assembly>


可使用的权限为

!-- 普通权限 -->
< requestedExecutionLevel level="asInvoker" uiAccess="false" />

!-- 管理员权限 -->
< requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

< !-- 最高权限 -->
< requestedExecutionLevel level="highestAvailable" uiAccess="false" />


二 VC6  使用方法


Win7/8 是以一份程序集清单 Assembly Manifest 文档来获取程序需要的权限信息的,

这份清单可以两种方式:

方法1: 以外置文件形式来和程序放置在一起。而使用外置形式的图标没有盾牌标志。

对于外置程序集清单,可以将上述内容的文件以 应用程序名.Manifest 的文件名和程序放置在同一目录下即可,比如名为 test.exe 的应用程序集清单应命名为 test.exe.manifest 。

< ?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>

方法2:  以资源形式内嵌入应用程序,如果你能够重新编译程序,则可使用这一种,使用内嵌式程序清单的程序在 Win7/8 中的图标会有盾牌标志。

 1 在 VC6 中切换到资源视图,在资源节点上点击右键,选择 “Insert”插入新资源。
   选择自定义资源类型 "Custom",并输入类型:24VC程序执行时自动请求以管理员权限执行


  在该资源上点击右键,设置资源 ID 为 1


VC程序执行时自动请求以管理员权限执行



   3 双击该资源类型 24,将上述 manifest 文件内容粘贴到资源里,保存,然后重新编译生成应用程序即可。

VC程序执行时自动请求以管理员权限执行


https://img-blog.csdn.net/20180618232848535?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3doeTE5OTQwOTI2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有