Chinaunix首页 | 论坛 | 博客
  • 博客访问: 47227
  • 博文数量: 1
  • 博客积分: 1430
  • 博客等级: 上尉
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-20 04:05
个人简介

对各种开发语言都有兴趣的专注于iOS、mac平台开发的coder。

文章分类

全部博文(1)

文章存档

2009年(1)

我的朋友
最近访客

分类: WINDOWS

2009-05-21 21:14:55

在Vista下提升应用程序的执行权限

在vista系统应用程序执行时默认不会使用超级用户权限,这会使一些创建文件和目录的IO操作失败,出现访问错误.这种现象是因为Vista的UAC特性引起的.

要避免这种情况,可以强制用户在运行应用程序时以超级用户权限执行程序.具体做法:

1.编辑manifest文件. 在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="IsUserAdmin"
     type="win32"/>
     
  <description>Description of your application</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>

 </assembly>


2.编辑应用程序的资源文件(rc后缀的文件),在其中加入下面两行代码:

#define MANIFEST_RESOURCE_ID 1
MANIFEST_RESOURCE_ID RT_MANIFEST "{Application.exe}.manifest"


其中Application.exe替换成要编译生成的可执行文件名.

3.编译链接程序,生成可执行应用程序.

4.运行mt.exe命令,把manifest文件和生成的可执行程序链接起来.把manifest内容写入可执行文件.
命令行为:

mt.exe –manifest temp.manifest –outputresource:YourApp.exe;#1


到这一步,生成的可执行文件就可以在vista下运行时弹出UAC确认框,让用户确认以超级用户权限执行应用程序.

参考:
1.
Designing UAC Applications for Windows Vista

2.
AC: User Account Control



阅读(801) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~