WISDOMBAY

in4mation ... organized

Dealing with NSIS made Simpler

Page 3

Posted by Mohammed Arfath

;;Checking IF This Program Is Already Installed
ReadRegStr $R0 HKLM "Software\${product_name}" "Install_Dir"
StrCmp $R0 "" notinstalled 0
MessageBox MB_YESNO "${product_name} is Already Installed in $R0.Do you want to reinstall?" IDYES true IDNO false
true:
ReadRegStr $R1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}" "UninstallString"
;HideWindow
ClearErrors
Execwait '$R1 _?=$INSTDIR' $0
IfErrors 0 +5
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}"
DeleteRegKey HKLM "SOFTWARE\${product_name}"
messagebox MB_OK "Error in uninstaller-$R0\${product_name}\uninstall.exe"
goto false
intcmp $0 0 +3
messagebox MB_OK "Unsuccessful Uninstallation"
Goto false
Goto notinstalled
false:
Abort
notinstalled:

FunctionEnd


Function myGUIInit
;setting the background image
InitPluginsDir
File /oname=$PLUGINSDIR\1.bmp "${background_image}"
BgImage::AddImage /NOUNLOAD $PLUGINSDIR\1.bmp 150 0
BgImage::SetBg /NOUNLOAD /FILLSCREEN "$PLUGINSDIR\1.bmp"
BgImage::Redraw /NOUNLOAD
FunctionEnd

Function .onGUIEnd
BgImage::Destroy
FunctionEnd

Function .onInstSuccess
;;uncomment the following lines if you want to copy your dlls and ocx files to the system directory
;CopyFiles /SILENT "$INSTDIR\${product_name}\mydll.dll" "$SYSDIR"
;CopyFiles /SILENT "$INSTDIR\${product_name}\myocx.ocx" "$SYSDIR"

;;uncomment the following lines if you want to just want to register your dlls and ocx files in your application directory
;ClearErrors
;RegDLL "$INSTDIR\${product_name}\mydll.dll"
;IfErrors 0 +2
;messagebox MB_OK "Error In Registering $INSTDIR\${product_name}\mydll.dll"
;ClearErrors
;RegDLL "$INSTDIR\${product_name}\myocx.ocx"
;IfErrors 0 +2
;messagebox MB_OK "Error In Registering $INSTDIR\${product_name}\myocx.ocx"

FunctionEnd

After copying the above code to your Modern.nsh file and editing the “;variable initialization section”, we are ready to create the installer.

Step 4 : Installer creation

Open the NSIS Menu. (NSIS Menu can be opened from the desktop or from start menu).
Select the option “Zip2exe” from the available options. A folder browser will be opened asking for your zip file. Select the file Myapp.zip that we created in the Step 2, and then click “Generate” button. Another window will be opened, showing the status of compilation. Remember that all the buttons in that window will be disabled until the compilation is over.

And that’s it, Creating Installer’s with NSIS is as simple as the above given 4 steps.


If you have any queries regarding the use of NSIS feel free to contact me at arfath@wisdombay.com arfath@wisdombay.com

Google