开发者

How do I deploy applications in run as administrator mode?

How Do I deploy applications so that they require administrator rights witho开发者_如何学运维ut the end-user doing that by hand?

I use Delphi 2009 to build the application.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜