Thursday, 14 March 2013

Hello, world! in NSIS - the simplest NSIS script

NSIS requires two things to be present in a script:

1) call to OutFile function (in order to define installer's name and output directory)
2) at least one Section (NSIS script executes sections and each section can contain functions and instructions; functions contain instructions only)

So, the shortest script that compiles could be:


NSIS compiler creates HelloWorld-installer.exe in the same directory where HelloWorld.nsi resides. When run, installer looks like this:


If we click on Show details button, we can see the following:


We can use ShowInstDetails in order to make installer displaying details by default:

We can use DetailPrint in order to output our custom messages:

And so Installer displays our custom text and Details window by default:


If we want to perform some system checks when installer starts, we can place our code in predefined function .onInit. In the next example, we'll just put displaying message box:

When we run installer, message box is first displayed:


When we click on OK, main window shows:


I used instruction Name to customize title of Installer's windows.

We can do some more serious stuff in .onInit function, like Windows version check. Download GetWindowsVersion.nsh header, create directory headers in the same directory where HelloWorld.nsi is, place GetWindowsVersion.nsh in that new directory (as we want to keep downloaded scripts separately from our work), include that header in the script and call function it exposes - GetWindowsVersion:

Message box displays Windows version:


NOTE: Files with extension nsi are installer script files and files with extension nsh are installer headers.

NOTE: DetailPrint calls from .onInit are ignored.

1 comment:

micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : ( ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;