Tuesday, March 20, 2012

Write your first NSIS script

- Mohankumar Deivasigamani
NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers. It has a flexible design and is therefore very suitable for internet distribution. You can Google NSIS.

This article introduce how to write and compile your first NSIS script . I strongly recommend you to correctly install the NSIS on your computer.
As its been tradition to start of with the “Hello World” as first program , which does nothing more but show a simple "Hello World" message box . To create a program you'll need a text editor (like Notepad) or you install HM NIS EDIT it’s a free NSIS Editor. Ref: http://hmne.sourceforge.net/

Let’s Start 
Open notepad or NSIS editor, you can either type the program shown below into notepad or just copy-paste it from this article

HelloWorld.nsi - First NSIS Script
Written by - Mohankumar Deivasigamani
# Name of the installer
Name "CSS Corp Labs"
OutFile "CSSCorp.exe"
XPStyle on
  Function .onInit
      MessageBox MB_OK "Hello World …"

Once you finish typing your script you should Save the NSIS script file as HelloWorld.nsi. In fact after making any changes to your source code, you should always save the file. Once save script done close the notepad. Right click on the file, you will see two context menus (Compile NSIS Script & Compile NSIS Script [Choose Compressor]) to compile the NSIS script

  1. Compile NSIS Script will use default compressor that you defined in script.
  2. Compile NSIS Script [Choose Compressor] will allow you to choose compress type. (ZLIB, ZLIB (solid), BZIP2, BZIP2 (solid), LZMA, & LZMA (solid)).

Once you choose compressor type and say ok, the script is compiled and generate exe file in name that you specified in OutFile property.

After you compile, Make NSIS window will help you test your installer by clicking the “Test Installer” button. This creates Installer where your script is saved.

Double click to test the installer.

No comments: