如何将<requestedPrivileges>信息添加到Delphi项目的清单中

20

如何在Delphi XE项目(.exe)中添加<requestedPrivileges>清单信息最简便的方法是什么?

是否可以只添加所需节点,例如:

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

我是否需要添加整个清单文件,例如:

<?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> 

如果我必须添加整个清单文件,那么我是否会与内置的清单文件发生冲突(当项目选项“激活运行时主题”设置为true时生成)?


2
你需要添加整个清单(manifest),并禁用“激活运行时主题”。你可以使用资源编译器编译它,也可以包含一个单独的.manifest文件。 - Jens Mühlenhoff
3个回答

17

以下是一些链接

Delphi和Windows Vista用户帐户控制

Vista UAC清单

以下是步骤:

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>

将这个XML文件命名为YourApplicationName.manifest

创建一个文本文件,内容如下:

1 24 "YourApplicationName.manifest"

使用命令行执行以下命令,将此文本文件命名为YourApplicationName.RC:

brcc32 YourApplicationName.RC -foYourApplicationName.REC

这将创建一个名为YourApplicationName.REC的新资源文件。将该YourApplicationName.REC文件复制到您应用程序的资源路径中。在您的应用程序的DPR中包含此资源文件,例如:

{$R YourApplicationName.REC} 最后编译您的应用程序-现在可以获得管理员权限了。


2
今天我感觉有些迟钝。你能否解释一下那些链接是如何回答这个问题的?请在这里总结它们的内容,或者指出那些文章中对于当前任务最重要的部分。 - Rob Kennedy
8
没有必要(也不应该有任何开发环境要求您)降至命令提示符或运行单独的命令。只需将您的资源脚本添加到项目中(项目 -> 添加到项目 -> wumpa.rc -> 打开),Delphi现在会编译资源脚本。另外请注意,资源脚本文件可以使用任何您想要的名称。我们总是称其为wumpa.rc,就像“Hunt the wumpa”一样-这是对于发现Delphi(不像Visual Studio)能够编译资源脚本所需付出的工作量的参考。 - Ian Boyd
清单文件必须被称为<appliationname>.manifest,还是<SomeGenericName>.manifest也可以工作? - dummzeuch

13

你应该添加整个清单(manifest)。你需要禁用项目中IDE生成的版本。

这样做的好处是你将完全透明地控制你的清单。例如,你可能想要添加一个DPI感知(DPI aware)条目,以使你的应用程序在更高的字体缩放值下看起来更好。


9

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接