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

发布于 2024-08-04 22:14:33 字数 502 浏览 2 评论 0原文

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

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

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

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.

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

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

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:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还不是爱你 2024-08-11 22:14:33

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

正确的命令行是:

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

You should use /outputresource instead of /updateresource:.

The correct command line would be:

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;#1"
吐个泡泡 2024-08-11 22:14:33

这对我的 VS 2005 有用:

  1. 创建以可执行文件命名的文本文件,扩展名为清单,并确保它位于与代码文件相同的路径中;例如,如果您的应用程序名称是 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. 在您的可执行项目上,添加以下构建后事件:

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

希望这会有所帮助。祝你好运! -马特·埃斯特拉克

This worked for me for 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:
    <?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)"

Hope this helps. Good luck! -Matt Esterak

情痴 2024-08-11 22:14:33

您还可以像这样使用它来将清单嵌入 EXE 文件中:

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文