20

What is the easiest way to add the <requestedPrivileges> manifest info to a Delphi XE project (.exe)?

Is it possible to add just the required node like:

<requestedPrivileges>   
  <requestedExecutionLevel level="requireAdministrator"/> 
</requestedPrivileges>

or do i have to add the whole manifest file, like?

<?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="VistaLogonCustomizer.exe" type="*"/>
  <description>elevate execution level</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
   <security>
     <requestedPrivileges>
      <requestedExecutionLevel level="requireAdministrator"/>
     </requestedPrivileges>
   </security>
  </trustInfo>
  <dependency>
   <dependentAssembly>
     <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
   </dependentAssembly>
  </dependency>
</assembly> 

If I have to add the whole manifest file, do I have then a conflict with the build in manfest file (which is generated when the project-option "Activate Runtime-Theme" is set to true)?

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
markus_ja
  • 2,931
  • 2
  • 28
  • 36
  • 2
    You have to add the whole manifest and you have to disable "Activate Runtime-Theme". You can either compile it using the resource compiler or include a separate .manifest file. – Jens Mühlenhoff Jun 03 '11 at 13:24

3 Answers3

17

Here are some links

Delphi and Windows Vista User Account Control

Vista UAC Manifest

Here are the steps:

Create XML file with following content: 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.1.1.1"
   processorArchitecture="X86"
   name="YourApplicationExeName"
   type="win32"/>
  <description>elevate execution level</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  <security>
   <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
   </requestedPrivileges>
  </security>
  </trustInfo>
 </assembly>

Name this XML file as YourApplicationName.manifest

Create a text file with following content:

1 24 "YourApplicationName.manifest"

Name this text file as YourApplicationName.RC using the command line execute following command:

brcc32 YourApplicationName.RC -foYourApplicationName.REC

This will create a new resource file called YourApplicationName.REC Copy this YourApplicationName.REC file in to the resource path of your application. Include this resource file into the DPR of you application,

as like:

{$R YourApplicationName.REC} Finally build your application - it is now ready to get admin rights

Community
  • 1
  • 1
Orhan Cinar
  • 8,403
  • 2
  • 34
  • 48
  • 2
    I'm feeling dense today. Could you please explain how those links answer the question? Summarize their contents here, or point out which parts of those articles are most important for the immediate task. – Rob Kennedy Jun 03 '11 at 21:22
  • 8
    There is no need (nor should any development environment require you) to drop to a command prompt or run a separate command. Just add your resource script to the project (**Project** -> **Add to project** -> `wumpa.rc` -> **Open**). Delphi will now compile the resource script. Also note, the resource script file can be called whatever you want. We always call it `wumpa.rc`, as in *Hunt the wumpa* - a reference to the amount of work to discover that Delphi (unlike Visual Studio) can compile resource scripts. – Ian Boyd Nov 15 '11 at 19:16
  • Is it a requirement that the manifest file must be called .manifest or would .manifest also work? – dummzeuch Feb 20 '13 at 10:52
13

You should add the entire manifest. You'll need to disable the IDE generated version in the project.

The advantage of this is that you will have full and transparent control of your manifest. For example you may want to add a DPI aware entry so that your app looks good at higher font scaling values.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
9

Is it possible to add just the required node

Absolutely NO. Manifest is an XML document and XML documents must be well-formed. Here is XML schema description:

http://msdn.microsoft.com/en-us/library/aa374191(VS.85).aspx

Note the required elements and attributes.

Premature Optimization
  • 1,917
  • 1
  • 15
  • 24