2009-09-14 80 views
24

我試圖使用mt.exe從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. 

當然,資源沒有在文件中找到 - 該文件沒有清單,這就是爲什麼我想添加一個。

如何將清單附加到可執行文件?這不應該簡單嗎?

回答

22

您應該使用/outputresource而不是/更新資源:

正確的命令行是:

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

您也可以使用這樣的嵌入EXE文件中的清單:

mt.exe -nologo -manifest「R:\共享\ hl.exe.manifest」 -outputresource: 「R:\共享\ hl33m.exe 1」

7

這爲我工作的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)"

希望這有助於。祝你好運! -Matt Esterak

相關問題