windows程序 UAC设置,程序运行提示使用管理员权限运行的方法

在近期的任务中需要对光盘中的程序运行时获取管理员权限运行程序。这个功能的实现需要改变工程的配置。

在vs2015中,使用鼠标右击解决方案管理器中的工程->属性->链接器->清单文件。

将UAC执行级别改成 requireAdministrator (/level='requireAdministrator')

如果需要生成清单时,需要查看下清单文件.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <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>

经过测试发现,有时候不使用清单文件无法有效果,添加了清单文件后才有效果。

posted @ 2018-06-13 14:08  在左手  阅读(1647)  评论(0编辑  收藏  举报