NSIS File command not working after calling SetOutPath

I wrote a NSIS script which copies two MSI files to $INSTDIR\Installers directory and then execute them, it's pretty easy and following is the code

Unfortunately above code will not work and it's saying NSIS cannot find these two msi files, but I'm sure they existed!

 
Then I tried to put $INSTDIR at beginning of the path

Now a MSI Help Dialog pops up with information about how to use msiexec command.. Apparently it failed again.

 

To solve this issue, we need call SetOutPath before ExecWait, like following

The first three lines will copy SqlLocalDB.msi and OutsideX64.msi files to $INSTDIR\Installers, and the last three lines will install MSI files at $INSTDIR\Installers.

It's because that ExecWait (Exec, ExecShell) command will use $OUTDIR as working directory, and this path can be set by SetOutPath command (By default $OUTDIR is set to $INSTDIR).

If we don't call SetOutPath command explicitly before ExecWait, its working directory will be $INSTDIR\Installers, and it will try to install MSI files under $INSTDIR\Installers\Installers directory, which is apparently wrong.

 

(And this guy had same problem as well http://stackoverflow.com/questions/17105455/install-sql-server-2008-r2-express-sp2-with-nsis)

Outside In Viewer Quiet Install not working

I need to install Outside In Viewer component silently in my NSIS installer. The Outside In Viewer installer is a MSI file, to install it silently, we need run following command in command line.

msiexec /i OutsideX64.msi /q

Above command will finish immediately, but it's finished so soon that I think the installation is likely failed.

Since the command line didn't return anything, I need enable logging to check what's wrong with it

msiexec /i OutsideX64.msi /q /log log.txt

(Note that the log.txt file should be created in advance, otherwise an error message will show.)

In the log file we see such message

MSI (s) (C4:BC) [14:54:57:760]: Product: OutsideX64 -- Error 1303. The installer has insufficient privileges to access this directory: C:\Program Files\OIX. The installation cannot continue. Log on as administrator or contact your system administrator.

By reading this log message, we know we need run this installer as administrator

 

To request Administrator privilege, add following line into our NSIS installer (at first line)

 

NSIS delete registry value

I searched "nsis delete registry value" on google, but found that search results are not really helpful. So I decide to write this post to introduce how to delete registry value (or how to delete registry string).

Deleting registry value need use DeleteRegValue instruction

DeleteRegValue root_key sub_key value_name

If I need to delete a value named "DisplayName" under "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Pooler" (This is the entry name in Add/Remove Programs in Windows XP or Program & Features in Windows 7/8), I could use:

DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pooler" "DisplayName"

And we can check this value by using ReadRegStr and MessageBox:

ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pooler" "DisplayName"

MessageBox MB_OK $0

 

Have fun with NSIS!

NSIS start program automatically when Windows starts

I was asked to build a program that monitors employees' actions (e.g. which website is he viewing), it's used to send user actions logs, network requests logs, etc.  to center logging server. But I cannot ask user to run a program which will log their actions, so to start program automatically when Windows starts is necessary.

 

In summary, there are three methods to achieve this:

1. Add program to Run or RunOnce Key

2. Add program shortcut to Start Menu/Startup Folder

3. Register program as a service (But our program is a GUI application and Windows Service doesn't allow GUI, so we ignore this method)

 

Run/RunOnce Key

If the program path is written into Run key, then this program will start every time when System boots.

registry_run

We can write it into HKLM(HKEY_LOCAL_MACHINE) or HKCU(HKEY_CURRENT_USER), HKLM will apply settings to ALL users, while HKCU only applies settings to current user.

WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "Monitor" "X:\Monitor.exe"

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Monitor" "X:\Monitor.exe"

RunOnce key will only run program automatically when the system boots first time. And after Windows is loaded, entries under RunOnce will be removed (It's usually used when application needs configuration after system reboots).

 

Start Menu/Startup Folder

Actually, programs under Start Menu/Startup Folder will be started after those defined in "Run" key.

CreateShortCut "$SMSTARTUP\Monitor.lnk" "$INSTDIR\Monitor.exe"

 

Loading order of Run, RunOnce, StartUp folder

Programs defined in Run, RunOnce or StartUp will be loaded in following order:

(Login Screen)

HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
StartUp Folder
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

 

NSIS sidebar image not displayed

I want to add sidebar image to finish page of a NSIS installer, because the default empty area on the left side is too ugly:)

After reading documentation, I found that MUI_WELCOMEFINISHPAGE_BITMAP is used to specify sidebar image for both welcome page and finish page

Ok, after trying add it to installer script, I found it didn't work at all. Following is the source code

!include "MUI2.nsh"

!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-nsis.bmp"

!insertmacro MUI_PAGE_FINISH

Section
SectionEnd

Finally I found that !insertmacro MUI_LANGUAGE "English" is needed, and it must be placed after !insertmacro MUI_PAGE_*. (please check here)

So following code will work:

!include "MUI2.nsh"

!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-nsis.bmp"

!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

Section
SectionEnd

But following code will not work:

!include "MUI2.nsh"

!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-nsis.bmp"

!insertmacro MUI_LANGUAGE "English"

!insertmacro MUI_PAGE_FINISH

Section
SectionEnd

 

And if MUI_LANGUAGE is not defined, some text will not be displayed correctly in the installer.

Also MUI_WELCOMEFINISHPAGE_BITMAP will add sidebar image to Welcome page