您实际上并没有在 VB 中创建清单文件。 Windows 应用程序清单是一个标准文本文档,格式为 XML。您可以在记事本中创建它,并使用适当的文件名将其保存在应用程序的目录中(YourAppName.exe.manifest
).
Microsoft 在此处提供了更多信息:应用清单 http://msdn.microsoft.com/en-us/library/aa374191.aspx。它甚至包括一个示例清单,您只需将其复制并粘贴到空白文本文件中即可开始。
如果您希望应用程序提示用户进行提升,重要的是设置requestedExecutionLevel
to requireAdministrator
, 而不是asInvoker
。提供了有关通过 UAC 使用清单的具体信息here http://msdn.microsoft.com/en-us/library/bb756929.aspx.
因此,完整的示例可能如下所示:
<?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="*"
name="MyMagicalApplication"
type="win32"
/>
<description>Sample manifest for your super cool application</description>
<!-- Request version 6 of the common controls. -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"
/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
将清单嵌入可执行文件的传统方法是使用mt.exe utility http://msdn.microsoft.com/en-us/library/aa375649.aspx,作为 Windows SDK 的一部分提供。
The VB加速器网站 http://www.vbaccelerator.com/home/VB/Code/Libraries/XP_Visual_Styles/Using_XP_Visual_Styles_in_VB/article.asp还有一些有关在 VB 6 应用程序中嵌入清单的信息。具体来说,它说:
提供清单的方法有两种:最简单(但最不优雅)的方法是在磁盘上提供可执行文件的清单。假设您的应用程序名为 TimeSlot.exe。然后,如果您将上面的清单 XML 保存为
TimeSlot.exe.manifest
在与可执行文件相同的目录中,TimeSlot.exe 将自动获取 XP 样式。提供了 VB5 和 VB6 示例。如果您在运行应用程序之前重命名 .manifest 文件,则可以关闭 XP 样式。
更可靠的方法是将清单编译为应用程序中的资源。为此,清单必须显示为资源类型RT_MANIFEST
(24)带身份证CREATEPROCESS_MANIFEST_RESOURCE_ID
(1).由于某种奇怪的原因,你must还要确保生成的 XML 文件长度是 4 字节的偶数倍。例如,如果您的文件实际上是 597 字节,则需要在编译之前添加填充空间以使文件大小达到 600 字节。资源示例演示了如何使用资源编译器脚本(.rc 文件)和 RC.exe 创建此资源文件。
但如果你想嵌入清单自动地当您从 VB6 IDE 构建应用程序时,您会遇到一些困难。比 VB6 IDE 不支持构建后步骤,因此您不能简单地运行mt.exe
在命令行上为您执行此操作。那里are我在网上看到的一些实用程序声称可以自动为您嵌入清单,但我相信其中大多数都是较旧的实用程序,仅处理 ComCtl32.dll 的请求 v6。我不确定它们是否可以轻松扩展以包含 UAC 权限,但值得一试。以下是一些可以查看的链接:
- http://vb6zone.blogspot.com/2010/07/make-my-manifest.html http://vb6zone.blogspot.com/2010/07/make-my-manifest.html
- http://sourceforge.net/projects/ummm/ http://sourceforge.net/projects/ummm/
- http://www.vbforums.com/showthread.php?t=606736 http://www.vbforums.com/showthread.php?t=606736
- http://www.vbforums.com/showthread.php?t=430886 http://www.vbforums.com/showthread.php?t=430886