Elevated privileges for Delphi applications
BY CRAIG CHAPMAN · PUBLISHED 2015-06-08 · UPDATED 2015-06-08

One of my customers recently asked the question “How can I force my application to run as administrator, without the user having to select this option?” Good question…
In this post, I’ll be using RAD Studio to create a Delphi application, however, the same technique should work equally well for a C++ Builder project.
Around the launch of Windows Vista, I’d heard about UAC (User Access Control) and manifest files, but I’ve never really had cause to work with them. The applications that I’ve worked on have not required administrative privileges, nor the theming benefits of using manifest files. So I’m inexperienced with them.
I began searching around for information, and found lots of older solutions which didn’t exactly work, either because they’re for older versions of Delphi / Rad Studio, or because they’re for older windows versions than I’m using. Eventually, I was able to work out a method that does work, and I’d like to share that with you…
Start by creating a new VCL application, and save the project. You can name the project as you wish, but you’ll need it’s name later. For this example I’ve named my project “ManifestTesting.” Also, be sure it’s a VCL application, this technique should work equally well for FMX applications running on windows, however, it does apply to windows only, so FMX is not necessary here.



Now, you’ll need to create a new file containing the XML manifest code required to request elevated permissions.
Select File / New / Other..

Under “Other Files” select “Text File”

Type in “.manifest” as the extension for your file, in the dialog…

When you click “Ok”, a new file named ‘New1.manifest’ will appear under your project. Right click on it, and select “Save As”

Save the file with the same name as your project, but a .manifest extension. So, in this example, save it as “ManifestTesting.manifest”

Now, we need some content for this file. Open the file in the IDE, and paste the following…
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="ManifestTesting" version="1.0.0.0" processorArchitecture="x86"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<!-- Windows Vista application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--Windows 7-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--Windows Vista-->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
</assembly>
Notice the tag name=”ManifestTesting” on line 3. You need to alter this to the name of your own application.
Save this file, and now right click on your project file and select “Options”

Now under the ‘Application’ category in the tree, select the option to “Use custom manifest”

The box named “Custom Manifest” (beneath the drop-down) has an associated button, click it to browse for and locate your “ManifestTesting.manifest” file…

After you click “Ok” a few times to dismiss the dialogs, build your project and attempt to run it.
You’ll see an error message:

This is because your application now requires Administrative rights to run, but the IDE is not running as Administrator, and is therefore unable to launch the process.
If you attempt to run the executable outside the IDE, you’ll be prompted to permit it to run as Administrator, which is the desired result, but how can we resolve this issue using the IDE?
You might have noticed that when we elected to use a custom manifest file in the project options, we did so under the debug profile…

Go and restore this option to “Enable runtime themes”, then change the “Target” dialog to a release profile and set “Use custom manifest” for that profile. Again, select the custom manifest file. You’ll then have a debug profile which does not request Administrative privileges, and a release profile which does.
Another alternative (if you require Administrative rights during debug), is to run your IDE as administrator, which you could do permanently by appropriately altering it’s short-cut. Note, this is not advised, you should only use administrative rights for debugging those features which specifically require elevated rights.
http://chapmanworld.com/2015/06/08/elevated-privileges-for-delphi-applications/
Elevated privileges for Delphi applications的更多相关文章
- Real time profiler for Delphi applications
xalion提供的资源,这么强,还是免费的,快去试用! ✓ Detailed debug information (internal, TDS, MAP) ✓ Display informat ...
- [Windows Azure] Windows Azure Web Sites, Cloud Services, and VMs: When to use which?
This document provides guidance on how to make an informed decision in choosing between Windows Azur ...
- Delphi WebBrowser控件的使用(大全 good)
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- Delphi TWebBrowser
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- Delphi资源大全
A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. Inspired by awe ...
- Awesome Delphi
Awesome Delphi A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. ...
- 开源的Delphi性能调试工具
官网:http://dbg-spider.net/源码:https://github.com/yavfast/dbg-spider Real time profiler for Delphi appl ...
- Taking a screen shot of a window using Delphi code is rather easy.
Taking a screen shot of a window using Delphi code is rather easy. A screen shot (screen capture) is ...
- From MSI to WiX, Part 1 - Required properties, by Alex Shevchuk
Following content is directly reprinted from From MSI to WiX, Part 1 - Required properties Author: A ...
随机推荐
- ospf基本配置协议
OSPF(开放最短路径优先)协议是链路状态路由协议类.对于 IPv4 的 OSPF 当前版本号 OSPFv2,的版本号 John Moy 在 RFC 1247 中引入,并在 RFC 2328 中 ...
- Centos Apache和tomcat集成配置,同一时候支持PHP和JAVA执行
近期因为项目的须要,须要再原来执行Tomcatserver上支持PHP执行.非常显然,PHP执行使用的是Apacheserver.尽管Tomcat也属于Apache,可是并没有现有的环境,须要我们自己 ...
- java基础——try catch final
1.不管有木有出现异常,finally块中代码都会执行: 2.当try和catch中有return时,finally仍然会执行: 3.finally是在return后面的表达式运算后执行的(此时并没有 ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 微信,支付宝,支付异步通知验签,notify_url
在支付接口开发中 ,当用户支付完成之后,阿里或者微信会向我们服务器发送一个支付结果的通知,里边带有一系列参数:其中特殊的是签名类型,和签名(他们根据这些参数做出来的签名). 我们的得到这些参数之后要去 ...
- Internet protocol optimizer
A method for optimizing the throughput of TCP/IP applications by aggregating user application data a ...
- 分布式系统和CAP
帽子理论(CAP): C:Consistency,一致性, 数据一致更新,所有数据变动都是同步的 A:Availability,可用性, 好的响应性能,完全的可用性指的是在任何故障模型下,服务都会在有 ...
- [Linux] ssh秘钥对免密码登陆
准备两台linux服务器 a和b , 在a上使用ssh命令登陆b服务器 , 并且不用 输入密码 1.在a服务器上,比如是root用户 ,进去/root/.ssh目录 ,没有就创建, 就是进入家目录的. ...
- 在嵌入式程序中QT去掉鼠标指针
在像arm的QT编程当中,一般都是使用触摸来操作,当是我们运行程序的时候会发现总是有个鼠标箭头在那里,下面介绍种方法将其给去掉.这样就漂亮多了.在main()函数加入 #include <QWS ...
- 数据科学(data science)概览
0. 硬件平台设计 一种分层的体系结构: 自下到上依次是: 硬件层 分布式系统层 分布式管理层 分布式处理层 应用层: 1. 总论