【问题标题】:How do I add a manifest to an executable using mt.exe?如何使用 mt.exe 将清单添加到可执行文件?
【发布时间】:2010-11-28 06:03:37
【问题描述】:

我正在尝试使用 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.

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

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

【问题讨论】:

    标签: windows manifest winapi mt


    【解决方案1】:

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

    正确的命令行应该是:

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

    【讨论】:

      【解决方案2】:

      这对我来说适用于 VS 2005:

      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. 在您的可执行项目中,添加以下构建后事件:

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

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-01-04
          • 1970-01-01
          • 1970-01-01
          • 2019-05-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多