|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
1. IntroductionIn this article I will cover core essentials of Nullsoft Scriptable Install System or also known as NSIS with focus on deploying applications programmed in Microsoft .NET Framework. I will cover deploying common objects that will immediately give you the power to use the opensource installer today! 2. BackgroundAs a RAD NET programmer I have spent many months looking at different installer systems trying to find one that compliments my application. While my requirements could not be any simpler, it seemed if each installer system I looked at created a new hurdle while solving an inefficiency of previous rival installer. At first look, NSIS reminded me of C programming language. As a programmer who has strong focus on eye candy within applications I write, I never imagined NSIS being able to offer it all for free. It turns out NSIS slices and dices NET deployments. 3. Contents
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
The fastest way to edit a .nsi file is from Windows Explorer using right click context menu. Providing you have Notepad++ installed you will be looking at editable script with full syntax highlighting in a fraction of a second...
![]() |
At the heart of the NSIS are sections that perform specific installation tasks. These not only make it easier for managing your script but also make you installer more powerful by allowing the end user to control which aspects of your software are installed. Sections may be optional, hidden, bold, read only and unchecked.
![]() |
There is always 1 desktop in every business that is running XP SP0. This is a major problem cause it is going to crash NET Framework installer. Here is the code for checking MSI version and installing MSI 3.1 if required...
Section 'MSI 3.1' SEC02 #NOTE should be installed before NET and stuff
GetDLLVersion '$SYSDIR\msi.dll' $R0 $R1
IntOp $R2 $R0 / 0x00010000 ; $R2 now contains major version
IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
IntOp $R4 $R1 / 0x00010000 ; $R4 now contains release
IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
StrCpy $0 '$R2.$R3' ;.$R4.$R5' ; $0 now contains string like '1.2.0.192'
${if} $R2 < '4'
${if} $0 != '3.1'
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File 'd:\mmm.runtimes\WindowsInstaller-KB893803-v2-x86.exe'
ExecWait '$TEMP\WindowsInstaller-KB893803-v2-x86.exe /quiet /norestart' $0
DetailPrint '..MSI 3.1 exit code = $0'
Delete '$TEMP\WindowsInstaller-KB893803-v2-x86.exe'
${Else}
DetailPrint '..MSI $0 already installed !!'
${EndIf}
${Else}
DetailPrint '..MSI $0 already installed !!'
${EndIf}
SectionEnd
NSIS have 100 or so code articles on their site and you may want to check it out here http://nsis.sourceforge.net/Category:Code_Examples. However lets take a detailed look at current release and future release of NET Framework.
| NET20 | Whidbey |
2.0.50727 |
Major | 2005 |
| NET30 | WinFX |
2.0.50727 |
Bolt on | 2007 |
| NET35 | Orcas |
2.0.50727 + (NET20 SP1) |
Bolt on | 2007 |
| NET40 | Hawaii |
4.0.00000 + (NET35 SP1) |
Major | 2008 |
Firstly, it is not a good idea to uninstall NET Framework considering it is part of Vista. Secondly, I strongly recommend you stick to deploying NET20, which is the simplest in terms of dependencies, the fastest and the smallest in terms of footprints. And given that NET30 contains NET20, this is best option. It will be very interesting to see, just how many changes are allowed in NET35 codename "Orcas". I have noticed ListView flickering to one included fix in Windows.Forms 3.5, although Microsoft are holding back on majority of fix's for compatibility reasons.
Section 'NET Framework 2.0 SP1' SEC03
;registry
ReadRegDWORD $0 HKLM 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727' Version
${If} $0 == '2.1.21022'
DetailPrint '..NET Framework 2.0 SP1 already installed !!'
${Else}
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File 'c:\path.to.file\netfx20sp1_x86.exe'
ExecWait '$TEMP\netfx20sp1_x86.exe /quiet /norestart' $0
DetailPrint '..NET Framework 2.0 SP1 exit code = $0'
Delete '$TEMP\netfx20sp1_x86.exe'
${EndIf}
SectionEnd
Let's assume that your software needs to install an ODBC driver, and this needs to be installed with \quiet option. Your NSIS section should look like this...
Section 'MySQL ODBC 003.051.XXX' SEC02
DetailPrint '..Installing MySQL ODBC'
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File "c:\path.to.file\mysql-connector-odbc-3.51.22-win32.msi" # NOTE Dont forget to change to uninstall GUID
ExecWait 'MsiExec.exe /q /i $TEMP\mysql-connector-odbc-3.51.22-win32.msi' $0
DetailPrint '..MySQL ODBC Connector exit code = $0'
Delete '$TEMP\mysql-connector-odbc-3.51.22-win32.msi'
SectionEnd
And now for uninstalling...
Section Uninstall
.
.
ExecWait 'MsiExec.exe /q /X{88164D59-4FFD-4874-93BC-5E001A7938F3}' $0
DetailPrint '..MyODBC exit code = $0'
SectionEnd
You can get the GUID from registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\.
Now we have installed NET Framework you may want to install 3rd party Assemblies. The best way to do this is with gacutil.exe provided by Microsoft in NET20...
Section 'MySQL NET 005.000.XXX' SEC03
DetailPrint '..Installing NET connector'
;options
SetOutPath '$INSTDIR'
SetOverwrite ifnewer
;uninstall #if required, code added for cp user Jonathan [Darka]
;ExecWait '"$INSTDIR\gacutil.exe" /uf "$INSTDIR\MySql.Data"' $0
;file work
File 'c:\path.to.file\gacutil.exe'
File 'c:\path.to.file\MySql.Data.dll'
;install
ExecWait '"$INSTDIR\gacutil.exe" /silent /i "$INSTDIR\MySql.Data.dll"' $0 #FIX wasn't working without double quotes
DetailPrint '..MySQL NET Connector exit code = $0'
SectionEnd
NOTE ABOUT UNINSTALLING PREVIOUS ASSEMBLIES
1. ExecWait '"$INSTDIR\gacutil.exe" /uf "$INSTDIR\MySql.Data"' $0
2. /UF = Uninstall + Force
3. The above command will not work if you pass gacutil.exe the file extension ".DLL"
4. I have positive feedback about the FCT plugin which closes apps by window title.. sam6nz says "reliable and flexible"
And now for uninstalling...
Section Uninstall
.
.
;SEC05 – NET
;options
SetOutPath '$TEMP'
SetOverwrite on
;file work
File 'c:\path.to.file\gacutil.exe'
File 'c:\path.to.file\MySql.Data.dll'
DetailPrint '..Uninstalling MySql.Data.dll'
ExecWait '$TEMP\gacutil.exe /silent /u MySql.Data' $0
DetailPrint '..MySql.Data exit code = $0'
SectionEnd
This is actually same as 11. Un/Installing 3rd Party .MSI except we have to convert the .MSM to a .MSI file. For example lets assume you want to convert Crystal Reports 2005 .MSM to an standard .MSI file. Once the conversion is completed you can throw any standard install option flags at the .MSI file for example /q and it works like it would with any other .MSI file. The easiest way to achieve .MSM > .MSI this is through VS2005 Setup Project. See pictures below for instructions...
Adding MSM file to Setup Project...
![]() |
Some or most MSM files have various dependencies, for example if the MSM file you are trying to convert requires another MSM file such as C:\Program Files\Common Files\Merge Modules\Microsoft_VC80_ATL_x86.msm which is installed with VS2005 if you check 'Install Redistributables' during setup. If you don't have this file just run VS setup again and check the box.
![]() |
Here are some Installer Attributes (flags) I use and strongly recommend...
SetCompress off |
Speeds up installation |
CRCCheck on |
Verifies downloads and CDs |
RequestExecutionLevel user |
Uninstalls start menu item on Vista |
BrandingText "ACME Inc." |
Customizes installer wizard |
Here are some macros you may wish to include as extra...
!insertmacro MUI_PAGE_LICENSE "..\Folder\YourLicense.rtf"
For a rapid response try the NSIS forums http://forums.winamp.com/forumdisplay.php?s=315447ba88ebb577ca060ea8dcffa07d&forumid=65, although they may point you towards code example link I gave early.
If you need to debug your script, best thing to do is write debug info using DetailPrint and then throw in a MessageBox MB_ICONINFORMATION|MB_OK "Break point" , this will pause the installer until you can verify the point of failure.