16

Would anyone have an example of a manifest file for Delphi 7 which allows apps to run as administrator on Windows XP / Vista / 7?

Running an application with this feature usually leads to a User Account Control (UAC) dialog asking for privileged permissions.

4
  • 4
    Using highestAvailable, as suggested by Cosmin and Sigurdur, results in the program starting up without admin rights if the user is not an administrator. If your app can only do useful work if it runs with admin rights then you should use requireAdministrator instead. In the case that the user is administrator then the UAC approval elevation dialog will show. In the case that the user is a standard user then the UAC "over-the-shoulder" elevation dialog will show. Jan 21, 2011 at 10:55
  • Also, you mention XP but I don't believe you can manifest admin rights issues. On XP, if you want a standard user to run an app as admin then I believe you need to use RunAs. Jan 21, 2011 at 10:56
  • See also my previous answer to a similar question
    – shunty
    Jan 21, 2011 at 11:31
  • You can find an automated solution in this article.
    – avra
    May 31, 2011 at 7:32

4 Answers 4

24

Here are the steps:

1. Remove XPMan: Remove any reference to XPMan component in your project. XPMan adds a default manifest to the executable that prevents Windows to see our customized manifest. You shouldn't be worried about XP Theme provided by XPMan, theme support is preserved in the following manifest.

2. Create the customized manifest: Create a file like Win7UAC.manifest in the project directory (the filename really doesn't matter). add the following lines to Win7UAC.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="App" version="3.1.0.0" processorArchitecture="*"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <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>
      <!--The ID below indicates application support for Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!--The ID below indicates application support for Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    </application>
  </compatibility>
</assembly>

You can add more items to this manifest. You can also remove Microsoft.Windows.Common-Controls parts to disable the theme support.

3. Compile manifest to a resource: Create a file named Win7UAC.rc in the project directory that contains one line as:

1 24 "Win7UAC.manifest"

To compile this file, go to cmd, point to project directory and run following command:

brcc32.exe Win7UAC.rc

4. Add resource (the manifest) to the project: Just add the following line anywhere you want in one of the unit files of the project:

{$R 'Win7UAC.res'}

A suitable place for adding this line is in the project main file (usually named Project1.dpr) and under the {$R *.res} line.

5. Rebuild the project

6. Remember whenever you add XPMan component to any of project units, this UAC manifest will not work properly.

4
  • 2
    i'll save searching time for you guys... <!--The ID below indicates application support for Windows 8 --> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> {4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38} for Windows 8: Apps that set this value in the application manifest get the Windows 8 behavior
    – Rebelss
    Aug 7, 2013 at 13:50
  • After followed all these instructions, i get this error when trying to compile my project, any ideas ? "[DCC Error] E2161 Warning: Duplicate resource: Type 24 (user-defined), ID 1; File myproject.res resource kept; file Win7UAC.res resource discarded." Jan 27, 2016 at 17:13
  • @delphirules: I haven't tried this for a while. Are you sure you have done all the steps precisely? Let me know if you still had any trouble. I might be able to shoot up a Win7 VMWare and give it a try.
    – Isaac
    Jan 27, 2016 at 22:25
  • @Isaac I could solve this error by unchecking the option to use themes, on Project Options. It seems the manifest already do this, thank you ! Jan 28, 2016 at 0:13
6

Here are some informative links

Vista UI mainfest

Delphi and Windows Vista User Account Control

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="x86" />
    </dependentAssembly>
  </dependency>

  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="highestAvailable"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>
3
  • You include it by adding a rc file with 1 24 "ExecutionLevelHighestAvailable.manifest"
    – Sigurdur
    Jan 21, 2011 at 10:22
  • Just remember to remove the use of XPMan from all units of project.
    – Isaac
    May 30, 2011 at 16:14
  • Also, change processorArchitecture "x86" into "*" to support 64 bit platforms
    – PatrickvL
    Sep 13, 2011 at 10:46
2

This works fine for me:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          publicKeyToken="6595b64144ccf1df"
          language="*"
          processorArchitecture="x86"
        />
    </dependentAssembly>
  </dependency>

  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="highestAvailable" />
      </requestedPrivileges>
    </security>

</assembly>
2

Using Delphi XE, I had to uncheck 'Enable runtime themes' in 'Project' -> 'Options' -> 'Application' tab for this to work.

Edit: sorry, does seems to work with this option enabled.

1
  • In my case using Embarcadero C++ Builder XE, I did have to uncheck that option for working.
    – ruhalde
    Jul 24, 2012 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.