在Windows 7 下使用Visual Studio 2010 编写自动申请管理员权限运行的程序
自从Vista推出UAC之后,遇到程序需要执行一些高安全级别的操作的时候就需要系统管理员权限,如何让自己写的程序能够自动向系统申请管理员执行权限,也就是在程序的图标上出现一个小盾牌的图标呢,使用Visual Studio 2010可以很方便的做到这一点。具体步骤如下:
1、在项目中增加一个Application Manifest File
2、打开新增加的app.manifest文件,文件的内容如下:
<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" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
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>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->
</asmv1:assembly>
3、把<requestedPrivileges〉节中的配置项<requestedExecutionLevel level=" asInvoker" uiAccess="false" />改为<requestedExecutionLevel level=" requireAdministrator " uiAccess="false" />
4、重新编译程序,编译好后的程序图标上就会出现一个小盾牌,就可以以管理员身份启动了。
转载于:https://www.cnblogs.com/endlock/archive/2010/05/25/1743756.html
在Windows 7 下使用Visual Studio 2010 编写自动申请管理员权限运行的程序相关推荐
- EasyNVR摄像机H5流媒体服务器在windows上批处理脚本自动以管理员权限运行
很多时候, 我们需要以管理员权限来运行批处理脚本, 比如操作 windows 服务. EasyNVR 中提供安装服务的批处理脚本, 运行这个bat文件, 自动将 EasyNVR 以 windows 服 ...
- 如何在ubuntu中编写python_在ubuntu下使用visual studio code编写python
感觉有了visual studio code之后,不管编写什么语言的代码都可以,简单安装对应的语言插件即可. 这不轮到了最近比较热的python语言,蹭着AI的热度,python语言成为了工程师们又一 ...
- Win7 下使用 Visual Studio Code 编写运行 C 和 C++(环境搭建及使用方法)
系统环境:Win7 64bit 以下给出搭建步骤,每一步更细致的步骤,请查看下方链接: 第一步:下载安装编译器 MinGW-w64 (使用离线包似乎更可靠): 第二步:下载安装 Visual Stud ...
- 在 Windows Server 2008 R2 下用 Visual Studio 2010 编译 Chrome 与 WebKit Chromium Port
Ref: http://www.chromium.org/developers/how-tos/build-instructions-windows Ref:http://trac.webkit.or ...
- centos系统在Visual Studio Code 中使用超级管理员权限保存文件
第一种:使用root权限运行vscode sudo code --user-data-dir ="~/.vscode-root" 第二种: 在桌面图标处更改权限 每次更改之后会提示 ...
- Visual Studio 2010 的新机遇
中国是全世界最重要的开发工具市场之一,这主要体现在两个方面:首先,中国拥有150万专业开发人员,占全球第二位.其次,中国拥有250万IT专业人员,很多高级IT专业人员在程序编译或者办公软件的自动化方面 ...
- Visual Studio 2010——C#的主菜单的使用
实验环境:Windows XP,Visual Studio 2010 Ultimate 1 创建项目 文件>>新建>>项目,选中"Windows窗体应用程序&quo ...
- Visual Studio 2010—— C#的ComboBox控件使用
实验环境:Windows XP,Visual Studio 2010 Ultimate 1 创建项目 文件>>新建>>项目,选中"Windows窗体应用程序&quo ...
- Visual Studio 2010制作程序安装包
所谓程序安装包,可以简单理解为一种压缩包,即将你自己所写程序所需要的所有资源,如动态链接库dll.图标文件ico,甚至是调用的第三方可执行程序exe,打包并压缩.当用户运行该安装包时,再将相应的资源解 ...
最新文章
- LeetCode-笔记-112、路径总和
- BED文件如何排序,sort按列排序
- Machine Learning week 9 quiz: Recommender Systems
- JSP 中EL表达式用法详解
- 语言求余和乘除优先级_愉快地学Java语言:第二章基本程序设计 第2讲
- 用python编21点游戏_【Python3】21点游戏
- 关于websocket
- 我的2020(年终总结)
- android 转码工具下载,m3u8视频转码工具
- MySQL根据出生日期查询年龄,以及对年龄进行分组统计
- 读取二代身份证上的相片,函数GetBmp(char * Wlt_File,int intf) 怎么用?
- html整体结构图,用html+css制作的组织结构图
- VR相机市场杀出一匹黑马,SONICAM备受众筹用户追捧
- GIt登录不了,报错:Whoops, something went wrong on our end.
- Linux运维与架构工程实践
- 我方卧底发自美团的真实Android资料
- 电信光猫路由模式转桥接
- 傅老师课堂:Oracle高级查询之OVER (PARTITION BY ..)
- 系统光盘内容怎么考到计算机里,怎么把光盘内容复制到电脑上
- 酷客多小程序百城宣讲会-岳阳站圆满结束
热门文章
- 将本珊计算机组成原理,计算机组成原理,懂的老师帮忙解答下
- Linux中字符设备注册方式,3.4. 字符设备注册
- python sklearn 归一化_第3章 Sklearn概述
- wxpython 优秀的界面_wxPython 界面设计利器:wxFormBuilder 介绍
- stk 坐标系_STK中文用户手册.pdf
- 数学之美 系列七 -- 信息论在信息处理中的应用
- MYSQL多表查询与事务
- python框架-Django安装使用
- IDEA修改module的名字
- StringWriter/PrintWriter在Java输出异常信息中的作用