如何创建清单文件以具有管理员权限启动应用程序?

编程入门 行业动态 更新时间:2024-10-27 10:24:59
本文介绍了如何创建清单文件以具有管理员权限启动应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想为我的VB 6.0程序创建一个清单文件,以便在启动应用程序时,操作系统应向用户询问管理员特权.

I want to create a manifest file for my VB 6.0 program, so that when I launch my application, the OS should ask the user for administrator privilege.

我还想知道如何将其嵌入到应用程序中?

I also want to know how it can be embedded in the application?

推荐答案

您实际上并没有在VB中创建清单文件. Windows应用程序清单是标准的文本文档,格式为XML.您可以在记事本中创建它,并以适当的文件名将其保存在应用程序的目录(YourAppName.exe.manifest)中.

You don't actually create the manifest file in VB. A Windows application manifest is a standard text document, formatted as XML. You can create it in Notepad and save it with the appropriate file name in your application's directory (YourAppName.exe.manifest).

Microsoft在此处提供了更多信息:应用程序清单.它甚至包括一个示例清单,您可以将其简单地复制并粘贴到空白文本文件中以开始使用.

Microsoft has more information available here: Application Manifests. It even includes a sample manifest that you can simply copy and paste into a blank text file to get started.

重要的一点是,如果您希望应用程序提示用户提升海拔,请将requestedExecutionLevel设置为 requireAdministrator ,而不是asInvoker. 此处.

The important thing, if you want your application to prompt the user for elevation, is to set the requestedExecutionLevel to requireAdministrator, rather than asInvoker. Specific information on using manifests with UAC is available here.

因此完整的示例可能看起来像这样:

So a full sample might look something like this:

<?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实用程序,作为Windows SDK的一部分提供.

The traditional way to embed a manifest into an executable is using the mt.exe utility, available as part of the Windows SDK.

VBAccelerator网站也有一些有关在VB 6应用程序中嵌入清单的信息.具体来说,它说:

The VBAccelerator site also has some information about embedding manifests in a VB 6 application. Specifically, it says:

提供清单的方式有两种:最简单(但最不优雅)的方式是在磁盘上为可执行文件提供清单.假设您的应用程序名为TimeSlot.exe.然后,如果您将上面的清单XML保存为

There are two ways to provide the manifest: the simplest (but least elegant) way is to provide the manifest on disk for an executable. Let's say your application is called TimeSlot.exe. Then if you save the manifest XML above as TimeSlot.exe.manifest

在与可执行文件相同的目录中,TimeSlot.exe将自动获取XP样式.提供了VB5和VB6示例.如果在运行应用程序之前重命名.manifest文件,则可以关闭XP样式.

in the same directory as the executable, TimeSlot.exe will automatically get the XP styles. VB5 and VB6 examples are provided. If you rename the .manifest file prior to running the app, you can switch off the XP styles.

一种更可靠的方法是将清单编译为应用程序中的资源.为此,清单必须以ID为CREATEPROCESS_MANIFEST_RESOURCE_ID(1)的资源类型RT_MANIFEST(24)出现.出于某些奇怪的原因,您必须还必须确保生成的XML文件的长度是4字节的偶数倍.因此,例如,如果您的文件实际为597字节,则需要在编译之前添加填充空间以将文件大小调整为600字节.资源示例演示了如何使用资源编译器脚本(.rc文件)和RC.exe创建此资源文件.

A more robust method is to compile the manifest as a resource in your application. To do this, the manifest must appear as resource type RT_MANIFEST (24) with id CREATEPROCESS_MANIFEST_RESOURCE_ID (1). For some bizarre reason, you must also ensure that the resulting XML file is an even multiple of 4 bytes long. So for example, if your file is actually 597 bytes you need to add padding spaces to make up the file size to 600 bytes before compiling. The Resource examples demonstrate how to create this resource file using a resource compiler script (.rc file) and RC.exe.

但是,如果您想在从VB 6 IDE构建应用程序时自动嵌入清单,则会遇到更多困难. VB 6 IDE不支持生成后步骤,因此您不能简单地在命令行上运行mt.exe来为您完成此操作.我在网上看到了 几个实用程序,这些实用程序声称可以自动为您嵌入清单,但是我相信其中大多数都是较旧的实用程序,它们只能处理ComCtl32.dll v6的请求.我不确定它们是否可以轻松扩展以包括UAC权限,但是值得一试.以下是一些要签出的链接:

But if you want to embed the manifest automatically when you build your application from the VB 6 IDE, you're in for a little more difficulty. The VB 6 IDE doesn't support post-build steps, so you can't simply run mt.exe on the command line to do it for you. There are a couple of utilities I've seen around the web that claim to automatically embed manifests for you, but I believe most of these are older utilities that only handle requesting v6 of ComCtl32.dll. I'm not sure if they're easily extensible to include the UAC permissions as well, but it's worth a shot. Here are some links to check out:

  • vb6zone.blogspot/2010/07/make-my-manifest.html
  • sourceforge/projects/ummm/
  • www.vbforums/showthread.php?t=606736
  • www.vbforums/showthread.php?t=430886
  • vb6zone.blogspot/2010/07/make-my-manifest.html
  • sourceforge/projects/ummm/
  • www.vbforums/showthread.php?t=606736
  • www.vbforums/showthread.php?t=430886

更多推荐

如何创建清单文件以具有管理员权限启动应用程序?

本文发布于:2023-11-10 01:49:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   清单   管理员权限   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!