Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deploy applications in run as administrator mode?

How Do I deploy applications so that they require administrator rights without the end-user doing that by hand?

I use Delphi 2009 to build the application.

like image 261
Ivan Prodanov Avatar asked Mar 12 '10 11:03

Ivan Prodanov


2 Answers

You can inform Windows that your application needs to run as an administrator by using the requestedExecutionLevel element in your application manifest.

The manifest file is an XML file that looks as follows. It should be named YourApp.exe.manifest and placed in the same folder as the executable. (It can also be embedded in the resources of your application; it must have a resource type of RT_MANIFEST and an ID of 1.)

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="YourApp" type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

For further details on application manifests and how to create them, see Create and Embed an Application Manifest (UAC) at MSDN.

Note that the manifest is only respected by Windows Vista and later. If your user is running as a standard user on Windows XP, your application will not be launched as an administrator; you may need to write code to detect this if it will be a problem for your application.

like image 198
Bradley Grainger Avatar answered Sep 21 '22 03:09

Bradley Grainger


Another option, although not recommended for "every day applications", is to name your executable with "Install" or "Setup" as part of the name. Keep in mind that if you don't change any registry settings, or create any new files then windows will display a warning to the user that the program might not have run properly.

like image 34
skamradt Avatar answered Sep 21 '22 03:09

skamradt