Поделиться через


How to embed a manifest to an EXE file

This post explains in detail how to embed a manifest file into an executable (EXE) file. Embedding manifest files to EXEs is a requirement for the 'Certififed for Windows Vista' program (https://download.microsoft.com/download/8/e/4/8e4c929d-679a-4238-8c21-2dcc8ed1f35c/Windows%20Vista%20Software%20Logo%20Spec%201.1.doc)

For the purposes of this article, the term 'appname' refers to a sample application and should be replaced with the name of your application.

1. In Visual Studio 2005, open your application and go to the configuration manager. If you have x86 there already, click the drop down next to it and click <Edit…>. Find x86 in the list, select it and click Remove, the click Close. Now under Platform, click the drop down and select <New…>. Under New Platform, click the drop down and select x86. Under ‘Copy Settings From’, click the drop down and select <Empty>. Make sure the ‘Create New Solution Platforms’ checkbox is NOT checked. Click OK and Close to exit the configuration manager. Note: If you are using a post-build script to call MT.exe remove it as we will not need to use MT.exe to embed the manifest file.

2. Rebuild the application.

3. In VS 2005, click File, Close Solution.

4. Open notepad and paste the following into the new document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
          <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
               <security>
                    <requestedPrivileges>
                         <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
                    </requestedPrivileges>
               </security>
         </trustInfo>
</assembly>

5. Click File, Save As and save this file as appname.exe.manifest where ‘appname’ is the name of the application you built in Step 1. Close the file.

6. In VS 2005, click File, Open, File and browse to the location of your bin directory or where your EXE output is built and open appname.exe

7. In the main Visual Studio 2005 window you should see a treeview with appname.exe – expand that by clicking the plus (+) sign. Underneath you should have at least two nodes for ‘Icon’ and ‘Version’. Right click appname.exe and left click Add Resource. Click the Import button and browse to where you saved the file from Step 5 (the notepad file you named as appname.exe.manifest) and select it and click Open. You may need to change the Files of Type to All Files in order to see it. A ‘Custom Resource Type’ dialogue appears asking for a resource type – type RT_MANIFEST and click OK. This will add the manifest with a value of 101. Right click that manifest file and left click on Properties. Change the ID property from 101 to 1.

NOTE: If you want to verify the XML in the manifest is correct, double click the manifest in the tree view to see the binary. The ASCII data will be on the far right side.

8. Click File, Save and close the file.

9. If the .EXE file(s) you are working with is part of a ClickOnce deployment project you will need to update the ClickOnce application manifest and deployment manifest files since embedding a manifest to the executable file will change the hash of the file you are working with. You can use MageUI or Mage to do this. If using Mage.exe, open a command prompt and navigate to the directory where Mage.exe is stored and execute two commands:

mage.exe -u <path to appname.exe.manifest file>\appname.exe.manifest -Name "AppName" -Version 1.0.0.0 -FromDirectory <path to where the appname.exe.manifest exists> -cf <path to the .pfx file>\name.pfx -pwd "password if you used one"

where 1.0.0.0 is the version of your application

mage.exe -u <path to .application file>\appname.application -appm <path to appname.exe.manifest>\appname.exe.manifest -cf <path to the .pfx file>\name.pfx -pwd "password if you used one"

10. You are finished embedding the manifest to the .EXE file.

Comments