windows 如何使用 mt.exe 向可执行文件添加清单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1423492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:43:23  来源:igfitidea点击:

How do I add a manifest to an executable using mt.exe?

windowsmanifestwinapimt

提问by Colen

I'm trying to use mt.exe from the Windows SDK to add a manifest to an executable file that doesn't have one, using the following command line:

我正在尝试使用 Windows SDK 中的 mt.exe 将清单添加到没有清单的可执行文件中,使用以下命令行:

C:\winsdk61>mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -updateresource:"r:\shared\hl33m.exe;#1"

Unfortunately, when I do, I get this error:

不幸的是,当我这样做时,我收到此错误:

mt.exe : general error c101008c: Failed to read the manifest from
the resource of file "r:\shared\hl33m.exe". The specified resource
type cannot be found in the image file.

Of course the resource wasn't found in the file - the file doesn't have a manifest, that's why I want to add one.

当然,在文件中找不到资源 - 文件没有清单,这就是我想添加一个清单的原因。

How can I append a manifest to an executable file? Shouldn't this be simple?

如何将清单附加到可执行文件?这不应该很简单吗?

采纳答案by Cristian Adam

You should use /outputresourceinstead of /updateresource:.

您应该使用/outputresource而不是/updateresource:

The correct command line would be:

正确的命令行是:

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;#1"

回答by mesterak

This worked for me for VS 2005:

这对 VS 2005 对我有用:

  1. Create text file named after executable with extension manifest, and ensure it is located in the same path as your code files; i.e. Form1.cs, etc. For example, if your app name is UACTester.exe then your manifest file should be named UACTester.exe.manifest.
  2. Ensure the contents of the manifest is good. I use this one:
  1. 使用扩展名清单创建以可执行文件命名的文本文件,并确保它与您的代码文件位于同一路径;即 Form1.cs 等。例如,如果您的应用程序名称是 UACTester.exe,那么您的清单文件应命名为 UACTester.exe.manifest。
  2. 确保清单的内容是好的。我用这个:
    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
     xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" 
     xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
            <security>
                <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                    <requestedExecutionLevel level="requireAdministrator" 
                     uiAccess="false" />
                </requestedPrivileges>
                <applicationRequestMinimum>
                    <defaultAssemblyRequest permissionSetReference="Custom" />
                    <PermissionSet class="System.Security.PermissionSet" 
                     version="1" ID="Custom" SameSite="site" />
                </applicationRequestMinimum>
            </security>
        </trustInfo>
        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
            <application>
            </application>
        </compatibility>
    </asmv1:assembly>
  1. On your executable project, add the following post-build event:

    "$(DevEnvDir)..\Tools\Bin\mt.exe" -nologo -manifest "$(TargetPath).manifest" -outputresource:"$(TargetPath)"

  1. 在您的可执行项目上,添加以下构建后事件:

    "$(DevEnvDir)..\Tools\Bin\mt.exe" -nologo -manifest "$(TargetPath).manifest" -outputresource:"$(TargetPath)"

Hope this helps. Good luck! -Matt Esterak

希望这可以帮助。祝你好运!-马特·埃斯特拉克

回答by user403103

You can also use it like this to embed the manifest inside the EXE file:

您也可以像这样使用它在 EXE 文件中嵌入清单:

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;1"

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;1"