Using !packhdr: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
m (→‎Usage: interwikis)
 
(7 intermediate revisions by one other user not shown)
Line 2: Line 2:


== !packhdr ==
== !packhdr ==
!packhdr is a useful compile time directive which allows modifications to the built installer executable header before it is written to the finished installer executable file.
!packhdr is a useful compile time directive which allows modifications to the built installer executable header before it is written to the finished installer executable file. It can be used in conjunction with some useful batch files to:
It can be used to pack the executable header using UPX or edit resources using Resource Hacker. I have used !packhdr for many years in conjunction with some useful batch files to:


* Pack the header (UPX)
* Pack the header (UPX)
* Pack the header (UPX) and remove the installer icon (Resource Hacker)
* Remove the installer icon (Resource Hacker)
* Add additional supported OS GUIDs for Windows 8 and above detection in NSIS 2.46


== Batch files ==
== Download ==
Firstly you will need to download [http://upx.sourceforge.net/#download UPX] and [http://angusj.com/resourcehacker/ Resource Hacker] and copy upx.exe and reshacker.exe to a new NSIS\Packhdr folder. Then place the following batch files in the NSIS\Packhdr folder:
# Extract the contents of <attach>Packhdr.zip</attach> to your NSIS directory
 
# Download [http://upx.sourceforge.net/#download UPX] and [http://angusj.com/resourcehacker/ Resource Hacker] and copy upx.exe and reshacker.exe to the NSIS\Packhdr folder
'''upx.bat'''
<pre>
cd /d %~dp0
 
upx --best %1
</pre>
'''upx+noicon.bat'''
<pre>
cd /d %~dp0
 
ResHacker -delete %1, %1, icongroup,103,
del ResHacker.log
 
upx --best %1
</pre>


== Usage ==
== Usage ==
Simply place the following at the top of your NSIS scripts:
<highlight-nsis>
<highlight-nsis>
!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\Packhdr\upx.bat" "$%TEMP%\exehead.tmp"`
!define Packhdr noicon+upx
!define RequestExecutionLevel admin
!include Packhdr.nsh
</highlight-nsis>
</highlight-nsis>
You can substitute ''upx.bat'' with ''upx+noicon.bat'' depending on your requirement for the particular installer. I use ''upx+noicon.bat'' for utility executables that are written in NSIS but do not serve a purpose as an installation wizard (i.e. ''SilentInstall silent'').
== Script header ==
You can put this code into an NSH file and place it in your NSIS\Include folder:
<highlight-nsis>
!ifndef _Packhdr_Included
!define _Packhdr_Included
!ifndef Packhdr
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx+noicon
  !define _Packhdr_Error
!endif
!ifdef _Packhdr_Error
  !error `Packhdr not defined correclty! Possible values: upx | upx+noicon`
!endif


!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\packhdr\${Packhdr}.bat" "$%TEMP%\exehead.tmp"`
'''For all NSIS versions'''
* ''!define Packhdr upx'' for all installers to reduce their header size.
* ''!define Packhdr noicon+upx'' for installers or utilities written in NSIS that do not require an icon.
* ''!define Packhdr noicon'' for when you do not require an icon and have appended client data to the end of the executable that you do not want to compress.


!undef Packhdr
'''For NSIS 2.46'''
* ''!define RequestExecutionLevel'' is a replacement for the '''RequestExecutionLevel''' installer attribute while also embedding the additional supported OS GUIDs. Supported values are ''admin'', ''user'' and ''highest''.


!endif
'''For NSIS 3.0+'''
</highlight-nsis>
* You don't need to use the ''RequestExecutionLevel'' define; use the '''[[Reference/ManifestSupportedOS|ManifestSupportedOS]]''' installer attribute (in conjunction with '''[[Reference/RequestExecutionLevel|RequestExecutionLevel]]''') instead.


[[Category:Tutorials]]
[[Category:Tutorials]]

Latest revision as of 17:53, 14 January 2016

Author: Afrow UK (talk, contrib)


!packhdr

!packhdr is a useful compile time directive which allows modifications to the built installer executable header before it is written to the finished installer executable file. It can be used in conjunction with some useful batch files to:

  • Pack the header (UPX)
  • Remove the installer icon (Resource Hacker)
  • Add additional supported OS GUIDs for Windows 8 and above detection in NSIS 2.46

Download

  1. Extract the contents of Packhdr.zip (2 KB) to your NSIS directory
  2. Download UPX and Resource Hacker and copy upx.exe and reshacker.exe to the NSIS\Packhdr folder

Usage

!define Packhdr noicon+upx
!define RequestExecutionLevel admin
!include Packhdr.nsh

For all NSIS versions

  • !define Packhdr upx for all installers to reduce their header size.
  • !define Packhdr noicon+upx for installers or utilities written in NSIS that do not require an icon.
  • !define Packhdr noicon for when you do not require an icon and have appended client data to the end of the executable that you do not want to compress.

For NSIS 2.46

  • !define RequestExecutionLevel is a replacement for the RequestExecutionLevel installer attribute while also embedding the additional supported OS GUIDs. Supported values are admin, user and highest.

For NSIS 3.0+