highestAvailable比较灵活,毕竟大多数功能不需要系统最高权限(四种方法:屏蔽UAC,右键以管理员身份运行,增加manisfest,制作数字证书)
打开VS2005、VS2008、VS2010工程,查看工程文件夹中的Properties文件夹下是否有app.manifest这个文件;如没有,按如下方式创建:鼠标右击工程在菜单中选择“属性”,点击工程属性的“安全性”标签,在安全性标签页中勾选“启用ClickOnce安全设置”,并选择“这是完全可信的应用程序”,保存工程,此时在Properties下已经自动生成了app.manifest文件。
将默认的app.manifest文件修改为
- <?xml version="1.0" encoding="utf-8"?>
- <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
- xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
- <security>
- <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
- <!-- UAC Manifest Options
- If you want to change the Windows User Account Control level replace the
- requestedExecutionLevel node with one of the following.
- <requestedExecutionLevel level="asInvoker" uiAccess="false" />
- <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
- <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
- If you want to utilize File and Registry Virtualization for backward
- compatibility then delete the requestedExecutionLevel node.
- -->
- <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
- </requestedPrivileges>
- </security>
- </trustInfo>
- </asmv1:assembly>
配置文件修改后,我们运行应用程序,就会首先弹出这样一个提示框,点 Yes 后,程序才可以继续运行。
顺便说下,还可以通过一个方法了解到此时程序运行是不是管理员权限:
- public static bool IsAdministrator()
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
- return principal.IsInRole(WindowsBuiltInRole.Administrator);
- }
对于XML文件中引用的UAC执行权限级别,分别代表下列含义:
Value | Description | Comment |
asInvoker | The application runs with the same access token as the parent process. | Recommended for standard user applications. Do refractoring with internal elevation points, as per the guidance provided earlier in this document. |
highestAvailable | The application runs with the highest privileges the current user can obtain. | Recommended for mixed-mode applications. Plan to refractor the application in a future release. |
requireAdministrator | The application runs only for administrators and requires that the application be launched with the full access token of an administrator. | Recommended for administrator only applications. Internal elevation points are not needed. The application is already running elevated. |
asInvoker : 应用程序就是以当前的权限运行。
highestAvailable: 这个是以当前用户可以获得的最高权限运行。
requireAdministrator: 这个是仅以系统管理员权限运行。
默认情况下是 asInvoker。
highestAvailable 和 requireAdministrator 这两个选项都可以提示用户获取系统管理员权限。那么这两个选项的区别在哪里呢?
他们的区别在于,如果我们不是以管理员帐号登录,那么如果应用程序设置为 requireAdministrator ,那么应用程序就直接运行失败,无法启动。而如果设置为 highestAvailable,则应用程序可以运行成功,但是是以当前帐号的权限运行而不是系统管理员权限运行。如果我们希望程序在非管理员帐号登录时也可以运行(这种情况下应该某些功能受限制) ,那么建议采用 highestAvailable 来配置。
参考:http://blog.csdn.net/a316019667/article/details/8647237
----------------------------------------------------------------------------
uiAccess Values
Value |
Description |
---|---|
False |
The application does not need to drive input to the user interface of another window on the desktop. Applications that are not providing accessibility should set this flag to false. Applications that are required to drive input to other windows on the desktop (on-screen keyboard, for example) should set this value to true. |
True |
The application is allowed to bypass user interface control levels to drive input to higher privilege windows on the desktop. This setting should only be used for user interface Assistive Technology applications. |
Important Note: |
---|
Applications with the uiAccess flag set to true must be Authenticode signed to start properly. In addition, the application must reside in a protected location in the file system. \Program Files\ and \windows\system32\ are currently the two allowable protected locations. 参考:http://www.cnblogs.com/wangjei155/archive/2009/09/29/1576551.html |
Applications running at normal privilege levels are NOT allowed to communicate with (i.e.; send messages to) applications running at higher privilege levels (e.g. the SendMessage API reports success but your message never reaches the target application running at a higher privilege).
If your application needs to send messages to all applications, regardless of their privilege level:
1 - The uiAccess flag MUST be set to True in your application's manifest.
2 - Your code MUST be digitally signed (which means you must pay MS for a digital certificate).
3 - Your application MUST reside in a trusted location (e.g.; Program Files), otherwise the uiAccess flag is ignored (so much for the user choosing where to place your application on THEIR hard drive).
Regardless of the state of the uiAccess flag, your application will always be able to send messages/drive input to windows of applications running at privilege levels equal to or less than your own privilege level.
Another piece of information in case you are having trouble putting a manifest in your executable (i.e.; the application fails to run with Windows complaining that it failed to initialize properly or something): the size of your manifest must be an exact multiple of 4 (i.e. if it is 253 bytes/characters, then you must pad the end of the manifest text with three spaces).
参考:https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/4d2e1358-af95-4f4f-b239-68ec7e2525a9/uiaccess-in-manifest-files
解释可以自己添加数字证书:
Actually you can use makecert to create your own certificate, and then add the cert to your trusted certificate store to run the code on your own machine. More on how to do that here-
Additionally, I don't think the code signing cert has to be from Microsoft, but can be purchased from any digital certificate authority (like Verisign, Entrust, DigiCert, etc.).
I hope that gets you what you need to get your code working without any further investment.
-Westley
制作数字证书的过程:
If your application does not have a digital signature and has uiAccess=true in its manifest, it will fail with "A referral was returned from the server."
(No, notepad does not have a digital signature :)
Applications that request uiAccess=true must have a valid, trusted digital signature to execute.
Also, applications by default must reside in a trusted location on the hard drive (such as windows or program files) to receive the uiAccess privilege. They will still run if they are not in one of these locations, but they will not receive the privilege. You can disable this security feature through the local security policy mmc snap-in.
If you want to create a trusted "test" certificate to sign your application with so that you can use your application on your current machine, here's how:
NOTE: These instructions assume you have visual studio installed and are using a command prompt that has all the environment variables set to find SDK utilities such as makecert and signtool. If not, you will need to find these tools on your hard drive before running them.
***
1) Open an elevated command prompt
- Click start
- Find Cmd Shell or command prompt
- Right-click, click Run As Administrator
2) Create a trusted root certificate
- Browse to the folder that you wish to contain a copy of the certificate
- In the command shell, execute the following commands:
makecert -r -pe -n "CN=Test Certificate - For Internal Use Only" -ss PrivateCertStore testcert.cer
certmgr.exe -add testcert.cer -s -r localMachine root
3) Sign your file
- In the command shell, browse to the location of your exe
- In the command shell, type:
SignTool sign /v /s PrivateCertStore /n "Test Certificate - For Internal Use Only" /thttp://timestamp.verisign.com/scripts/timestamp.dll APP.exe
Where APP.exe is your application.
----------------------------------------------------------------------------
Delphi:Delphi程序必须在资源里面嵌入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"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
保存为UAC.manifest,这里文件是随意的。特别注意红色的“requireAdministrator”,这个表示程序需要管理员(Administrator)才能正常运行。
? 然后编辑一个RC文件,名称为uac.rc 如下所示:
1 24 UAC.manifest
其中:
1-代表资源编号
24-资源类型为RTMAINIFEST
UAC.manifest-前面的文件名称
? 用brcc32编译这个rc文件为res文件,如下所示:
brcc32 uac.rc -fouac.res
? 在程序里面加入
{$R uac.res}
让Delphi编译的时候,把uac.res编译进exe文件
? 把文件放到vista或win7下运行,就会看程序图标下面显示UAC盾牌标志了
注:直接修改exe属性,试了好像不灵啊。
参考:http://www.sieye.cn/showArticle.asp?nameID=201192722213483
----------------------------------------------------------------------------
1:关闭用户的UAC功能(显然这个方法对于客户来说有点不靠谱,但是这里我也提一下,因为我就是特别烦UAC的提醒,所以给关闭了,程序一直也没有报错)。
关闭方法“控制面板-用户账户和家庭安全-用户账户-用户账户控制设置”,设置为“从不通知”,保存,重启就OK了。
2:这个方法很简单,就是在运行的时候右键“以管理员身份运行”。也是可以解决此问题,但是对于那些只想直接单击就运行的用户来说,估计他们也还是难以接受。
3:这个方法就比较长些了,解决出发点也是从我们自己的程序来解决。我来写一下步骤:
参考:http://www.cnblogs.com/boyliupan/archive/2011/01/17/1937518.html
----------------------------------------------------------------------------
UAC的存在更多的意义在于让程序员明白一个程序不要申请多余的权限,这样可以在最大程度上保护用户的安全。正常的做法就是把用户数据配置文件放在AppData下,只是很多人都是以XP的惯性思维来做。
至于2005下加入manifest的方法,作者最后给的那个链接文章里面也提到了,通过命令行的方式调用mt.exe即可:
mt.exe –manifest temp.manifest –outputresource:YourApp.exe;#1.
highestAvailable比较灵活,毕竟大多数功能不需要系统最高权限(四种方法:屏蔽UAC,右键以管理员身份运行,增加manisfest,制作数字证书)的更多相关文章
- FreeSql 新功能介绍:贪婪加载五种方法
前言 FreeSql 在经过6个月的开发和朋友们的工作实践,不断的改进创新,目前拥有1500个左右单元测试方法,且每个方法内又复盖不同的测试面. 今天介绍 FreeSql 各种贪婪加载的姿势,作下总结 ...
- 为Delphi程序增加UAC功能(管理员身份运行exe)
相关资料:http://bbs.csdn.net/topics/320071356# 操作方法: 在Source\VCL目录下应该有这样两个文件sample.manifest和WindowsXP.rc ...
- C#怎么实现文件下载功能的四种方法
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- 找回MSI安装包Win7/Win8管理员身份功能
找回MSI安装包Win7/Win8管理员身份功能 从Vista开始,系统引入了UAC用户控制功能,即普通用户运行exe软件安装程序,支持使用普通账户/管理员身份分别进行安装,但是msi安装包只支持默认 ...
- Android点击Button实现功能的几种方法
Android中Button控件应该算作是比较简单的控件,然而,它的使用频率却是非常的高,今天,我在这里总结了三种常用的点击Button实现其功能的方法. 1.很多时候,我们在 ...
- web手工项目03-登录功能测试用例及缺陷编写-流程图画法-前后台下单及发货流程图-流程图设计测试用例方法-功能测试涉及到的四种数据库场景
回顾 注册功能测试(步骤,需求分析(输入分析,处理分析,输出分析),数据构造(有效等价类,无效等价类,有效数据,无效数据),编写用例,执行用例,缺陷报告) 轮播图功能测试(步骤,需求分析拆分测试点,测 ...
- 屏蔽鼠标右键功能JS
<script language="Javascript"> function hiderightKey(){ return false; } docum ...
- android 实现分享功能两种方法
当我想做一个智能的记事本的时候,我就在尝试自己写一组分享功能.后来才知道,原来每个社交软件中都有自己的分享接口. 这就大大减少了我们的代码量了. 第一种方法:特点--简单 package com.ex ...
- WPF编程,使用WindowChrome实现自定义窗口功能的一种方法。
原文:WPF编程,使用WindowChrome实现自定义窗口功能的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/arti ...
随机推荐
- (转载)MyEclipse github
最近Git火得如日中天,而且速度体验和团队模式都很不错.手头正好有个学生实训项目,时间紧任务重,而且学校内网管理太紧,所以就想借助于Internet的分布式开发,因此想到了Github. ...
- 手动创建Servlet--J2EE学习笔记
Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. 使用 Serv ...
- Linux网络相关命令小结
# ifconfig # ifup/ifdown # route -n # ip link show //显示本机所有接口信息 # traceroute # netstat //查看本机网络连接与后门 ...
- python matplotlib.plot画图显示中文乱码的问题
在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...
- DOM操作--表格点击行变色
点击表格行变色,这种网页效果应该还是比较常见的.大家应该看见了,我这里的效果是用DOM操作实现的,那么很多人会问什么是DOM操作,贴出代码之前我就和大家解释一下什么是DOM操作: DOM是Docume ...
- window.clearInterval与window.setInterval的用法(
window.setInterval() 功能:按照指定的周期(以毫秒计)来调用函数或计算表达式. 语法:setInterval(code,millisec) 解释:code:在定时时间到时要执行的J ...
- jQuery 遍历同胞(siblings)
同胞拥有相同的父元素. 通过 jQuery,您能够在 DOM 树中遍历元素的同胞元素. 在 DOM 树中水平遍历 有许多有用的方法让我们在 DOM 树进行水平遍历: siblings() next() ...
- JS异步阻塞的迷思
还是百度前端技术学院的“任务十九”可视化排序算法的题,在写出快速排序算法之后,要求用动画的形式把这个排序过程呈现出来.排序过程在CPU里不过是瞬间的事,但要转换成“缓慢的”动画效果给人类看,就不得不把 ...
- 删除svn密码方法
很多时候使用svn,我们需要切换svn账号,但是由于之前的账号已经选择了记住密码,那么我们应该如何删除svn密码来切换新的svn账号呢? 其实很简单,svn账号密码信息保存在电脑某一文件中,我们只要删 ...
- 343. Integer Break -- Avota
问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...