Monday 24 May 2010

Installer by Nullsoft Scriptable Install System


Tool: This is an open source tools. Which will give you an easy way to make your installer. NSIS software download link:

http://nsis.sourceforge.net/Download


How it is work: Basically this script will compress your exe, depended dlls, third party software’s, documents etc which is required to run your project. It will produce a single “Setup.exe” file. When you will install this setup file automatically it will write down everything in the computer registry to run your software properly. If you arrange your folder structure like depended dlls, exe, doc files etc. So it will be easy for you to upload that files during installer making.


IDE: There are some IDE to write down the script. But according to me “HM NSIS Edit 2.0.3” is the best one. It will provide you a wizard by clicking you can easily make your installer. Download link of that IDE:


http://www.mrtech.com/forums/index.php?PHPSESSID=0a1ef3d385a53f29fa4ede11669d6bed&topic=1090.msg2721#msg2721


You can choose options according to your requirement. After finishing your wizard you will get some script. But here I will explain some problem that I have faced:


1. When you select multiple language and its correspondence terms of service doc file. It was not working. So in the license page section write down the following line.


; License page

!insertmacro MUI_PAGE_LICENSE "$(MUILicense)"


2. If you want to install third party software you have to use the following code. You have to add it in a section.


Section 'name' SEC01

DetailPrint '..Installing name..'

;options

SetOutPath '$TEMP'

SetOverwrite on

;file work

File ".\path of software"

ExecWait 'MsiExec.exe /q /i $TEMP\Filename.msi' $0

DetailPrint '.. Name exit code = $0'

Delete '$TEMP\Filename.msi'

SectionEnd


I have added full code from my project here:

; Script generated by the HM NIS Edit Script Wizard.


; HM NIS Edit Wizard helper defines

!define PRODUCT_NAME "Application"

!define PRODUCT_VERSION "1.0"

!define PRODUCT_PUBLISHER "Application ApS"

!define PRODUCT_WEB_SITE "http://www.Application.dk"

!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\Application.exe"

!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"

!define PRODUCT_APP_REGKEY "Software\Application ApS\Application"

!define PRODUCT_UNINST_ROOT_KEY "HKLM"

!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"


; MUI 1.67 compatible ------

!include "MUI2.nsh"


; MUI Settings

!define MUI_ABORTWARNING

!define MUI_ICON ".\Application.ico"

!define MUI_UNICON ".\Application.ico"

!define MUI_TEXT_COLOR "FFFFFF"


; MUI Settings / Header

!define MUI_HEADERIMAGE

!define MUI_HEADERIMAGE_RIGHT

!define MUI_HEADERIMAGE_BITMAP ".\SB_Setupbar_Top.bmp"

!define MUI_HEADERIMAGE_UNBITMAP ".\SB_Setupbar_Top.bmp"

!define MUI_HEADER_TRANSPARENT_TEXT

; !define MUI_BGCOLOR "808080"


; MUI Settings / Wizard

!define MUI_WELCOMEFINISHPAGE_BITMAP ".\SB_Setupbar_Left.bmp"

!define MUI_UNWELCOMEFINISHPAGE_BITMAP ".\SB_Setupbar_Left.bmp"


; Language Selection Dialog Settings

!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"

!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"

!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"


; Welcome page

!insertmacro MUI_PAGE_WELCOME


; License page

!define MUI_LICENSEPAGE_RADIOBUTTONS

!insertmacro MUI_PAGE_LICENSE "$(MUILicense)"


; Directory page

!insertmacro MUI_PAGE_DIRECTORY

; Start menu page

var ICONS_GROUP

!define MUI_STARTMENUPAGE_NODISABLE

!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Application"

!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"

!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"

!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"

!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP

; Instfiles page

!insertmacro MUI_PAGE_INSTFILES

; Finish page

!define MUI_FINISHPAGE_RUN "$INSTDIR\Application.exe"

!insertmacro MUI_PAGE_FINISH


; Uninstaller pages

!insertmacro MUI_UNPAGE_INSTFILES


; Language files

!insertmacro MUI_LANGUAGE "English"

!insertmacro MUI_LANGUAGE "Danish"


; License Language

LicenseLangString MUILicense ${LANG_ENGLISH} ".\SoftwareLicenseEnglish.rtf"

LicenseLangString MUILicense ${LANG_DANISH} ".\SoftwareLicenseDansk.rtf"


; MUI end ------


Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"

OutFile "Setup.exe"

;RequestExecutionLevel admin

InstallDir "$PROGRAMFILES\Application"

InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""

ShowInstDetails hide

ShowUnInstDetails hide


Function .onInit

!insertmacro MUI_LANGDLL_DISPLAY

FunctionEnd


Section 'RuntimeRequisite' SEC01

DetailPrint '..Installing RuntimeRequisite'

;options

SetOutPath '$TEMP'

SetOverwrite on

;file work

File ".\debug\RuntimeRequisite\RuntimeRequisite.msi"

ExecWait 'MsiExec.exe /q /i $TEMP\RuntimeRequisite.msi' $0

DetailPrint '..RuntimeRequisite exit code = $0'

Delete '$TEMP\RuntimeRequisite.msi'

SectionEnd


Section "Application" SEC02

SetOutPath "$INSTDIR"

SetOverwrite ifnewer


File ".\debug\QtCored4.dll"

File ".\debug\QtWebKitd4.dll"

File ".\Application.exe"

File ".\Application_en.qm"

File ".\Application_dk.qm"

SectionEnd

section Shortcut

; Shortcuts

SetShellVarContext all

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

SetOutPath "$INSTDIR"

CreateShortCut "$DESKTOP\Application.lnk" "$INSTDIR\Application.exe"

!insertmacro MUI_STARTMENU_WRITE_END

SectionEnd


Section -AdditionalIcons

SetShellVarContext all

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"

CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"

CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"

CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"

CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Application.lnk" "$INSTDIR\Application.exe"

!insertmacro MUI_STARTMENU_WRITE_END

SectionEnd


Section -Post

WriteUninstaller "$INSTDIR\uninst.exe"

WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\Application.exe"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\Application.exe"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"

StrCmp $LANGUAGE ${LANG_DANISH} 0 english

WriteRegStr HKCU "${PRODUCT_APP_REGKEY}" "language" "danish"

Goto done

english:

StrCmp $LANGUAGE ${LANG_ENGLISH} 0 done

WriteRegStr HKCU "${PRODUCT_APP_REGKEY}" "language" "english"

done:

SectionEnd


Function un.onUninstSuccess

HideWindow

MessageBox MB_ICONINFORMATION|MB_OK "Application was successfully removed from your computer."

FunctionEnd


Function un.onInit

!insertmacro MUI_UNGETLANGUAGE

MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove Application and all of its components?" IDYES +2

Abort

FunctionEnd


Section Uninstall

SetShellVarContext all

!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP

Delete "$INSTDIR\${PRODUCT_NAME}.url"

Delete "$INSTDIR\uninst.exe"

Delete "$INSTDIR\Application.exe"

Delete "$INSTDIR\ QtCored4.dll"

Delete "$INSTDIR\ QtWebKitd4dll"

RMDir /r "$INSTDIR\debug"

RMDir /r "$APPDATA\Application"


SetShellVarContext all

Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"

Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk"

Delete "$DESKTOP\Application.lnk"

Delete "$SMPROGRAMS\$ICONS_GROUP\Application.lnk"

RMDir "$SMPROGRAMS\$ICONS_GROUP"

RMDir "$INSTDIR"


ExecWait 'MsiExec.exe /q /X{88164D59-4FFD-4874-93BC-5E001A7938F3}' $0

DetailPrint '..RuntimeRequisite exit code = $0'


DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"

DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"

DeleteRegKey HKEY_CURRENT_USER "Software\Application ApS"

SetAutoClose true

SectionEnd

No comments:

Post a Comment