Add Windows 8 Manifest To NSIS Installer

How do you get a Windows manifest into an NSIS installer executable? Believe it or not, NSIS will add most of what you need in the manifest for you, such as the Windows Common Controls manifest and the requested execution level for UAC.

Note, to set the execution level for lets say Administrator, add the following near the top of your NSIS script:

RequestExecutionLevel admin

NSIS will also add program compatibility entries for Windows Visa and Windows 7. But what do you do to add the Windows 8 compatibility entry? Here you can use the !packhdr instruction. Too add the Windows 8 manifest for one of my scripts, I added the !packhdr instruction towards the top of my script as show below.

!packhdr "$%TEMP%\MySetup.exe" 'header.cmd'

What this does is tell makensis.exe to create an intermediate compiled version of the setup named MySetup.exe in the users’s TEMP folder. It does not matter really what the name is. !packhdr then calls the batch file header.cmd. The contents of header.cmd are show below. It calls the Manifest Tool, MT.exe, included with Visual Studio or the Windows SDK, to update the manifest resource using the partial manifest file app.manifest.

header.cmd

mt.exe -manifest app.manifest -updateresource:%TEMP%\InstallAgentSE.exe;1

app.manifest

[source language=”xml”]
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
</application>
</compatibility>
</assembly>
[/source]

The !packhdr instruction can also be used do things like call the Reshacker utility to modify executable resources such icons and bitmaps. You need to use !packhdr to do any resource modification as makensis.exe will embed a CRC check into the final executable. If the executable is modified in any way after the CRC check is added, then the install will fail.

This entry was posted in NSIS, Windows 8 and tagged , . Bookmark the permalink.

One Response to Add Windows 8 Manifest To NSIS Installer

  1. NokiaN9User says:

    Yes, but there is one issue – you cannot add networked ( located in windows share ) file because you cannot alter !tempfile path in compile-time ( imho ). Please edit this article and help others not waste their time untill NSIS 3.x has not been in Gold 😉

Leave a Reply

Your email address will not be published. Required fields are marked *