Embedding other installers using NSIS - nsis

I an new to NSIS scripting. I want to create a custom installer which would wrap around another installer(FEKO). This method Embedding other installers suggested on the NSIS website did not work for me
The script compiles correctly but the embedded application is not installed. Here is the script
!include "MUI2.nsh"
!include "logiclib.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
#Name of the application we are trying to install
Name "FEKO"
# update this section to add 'contact' info
BrandingText "Please contact support at xyz#abc.com for any issues. "
# define the name of installer
OutFile "Custom_FEKO_6.2_Installer.exe"
# define default installation directory
InstallDir "C:\FEKO\6.2\"
DirText "Choose a directory where you want to install FEKO"
# start default section
Section "FEKO Installation"
# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
DetailPrint "Extracting FEKO Files into Installation Directory"
# specify files to go into the installation directory path
File /r "C:\Feko_Installer\*"
# set the current working directory
SetOutPath "$INSTDIR"
SectionEnd
Section "FEKO installation" FEKO
DetailPrint "Installing Feko"
# run the FEKO installer and wait for it to finish
File "C:\Feko_Installer\feko_distrib_6.2_win64.exe"
ExecWait "$INSTDIR\feko_distrib_6.2_win64.exe"
DetailPrint "Finishing up Installation"
SectionEnd

If the child installer needs admin privileges you need to put RequestExecutionLevel admin in your script. ExecWait (CreateProcess) fails if the exe has a manifest requesting elevation.
Correct quoting for ExecWait is: ExecWait '"c:\full\path\to\app.exe" /param1 "par am 2" /param3'

Related

How to wait for parent NSIS Installer to be finished, before executing the embedded installer?

I am trying to run an installer inside the Script of another installer.
The parent installer needs to be finished to run the embedded installer inside properly.
!include "MUI2.nsh"
Icon "C:\Users\user\Pictures\logo.ico"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
ExecWait "$INSTDIR/CM/CMInstaller.exe"
SectionEnd
So how do I wait for the parent installer before executing the CMInstaller.exe?
Thanks for answering!
EDIT:
As Anders pointed out, the -POST is not a specific section name, just place this section (containing your child installer) after the main install section, or use .onInstSuccess callback function
Original answer:
In our project, we use -Post section to do some post-installation operations like placing the uninstaller or shortcut on the desktop, which might not be the best practice because there's a -FinishComponents section for the specified situation, check here
Section -Post
SetShellVarContext all
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\Uninst.exe"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\Uninst.exe"
;Write install path registry
WriteRegStr HKLM "${PRODUCT_INSTALL_DIR_REGKEY}" "${PRODUCT_INSTALL_DIR_SUBKEY}" $INSTDIR
!insertmacro WriteInstallLog "Install_log.log" "Installation completed"
;Execute CMInstaller here
ExecWait "$INSTDIR/CM/CMInstaller.exe"
SectionEnd
And according to the NSIS documentation, there's also a callback function .onInstSuccess when the installation is done successfully

When I run the instaler in German locale installer UI is showing in German but the application UI is not showing in German using NSIS

When I run the installer in the German locale, installer UI is showing in German but the application UI is not showing in German. Instead it is showing in English.
For the Installer UI to work as per the locale I have created separate .nsh files (!include "CustomEnglish.nsh",!include "CustomGerman.nsh",!include "CustomItalian.nsh") and included those in my .nsi file. So it is working as expected.
For the application UI to work as per the locale, I am using the below check based on the Language and placing the files (created separate resouce dlls for each language) in the Installed directory.
Is it the correct way to place the dlls or files based on the locale in the Installed directory?
And also I am not using the statement !insertmacro MUI_LANGUAGE "English" in this .nsi file. Because this statement I am giving in the !include "CustomEnglish.nsh" (I have also attached CustomEnglish.nsh for the reference)
Please help me why the application UI is not showing in German?
Below is the complete code:
!include "MUI2.nsh"
!include x64.nsh
!include WinVer.nsh
Name "Millinnium 4.0"
RequestExecutionLevel admin
;RequestExecutionLevel user
; Below is the include file to check the conditions (If and else)
!include LogicLib.nsh
;Customizing the Welcome Text
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
${EndIf}
SectionEnd
;--------------------------------
Section "Uninstall"
SectionEnd
CustomEnglish.nsh
!insertmacro MUI_LANGUAGE "English"
!define ApplicationName "Millinnium"
LangString welcometitle ${LANG_ENGLISH} "Welcome to the ${ApplicationName} Setup Wizard"
LangString welcometext ${LANG_ENGLISH} "The Setup Wizard will install ${ApplicationName} on$\r$\nyour computer. Click Next to continue or Cancel to exit the$\r$\nSetup Wizard."
LangString licensetitle ${LANG_ENGLISH} "End-User License Agreement"
LangString licensesubtitle ${LANG_ENGLISH} "Please read the following license agreement carefully"
LangString licensecheckboxtext ${LANG_ENGLISH} "I &agree to terms in the License Agreement"
LangString mydirtoptext ${LANG_ENGLISH} "Install ${ApplicationName} to:"
LangString mydirtitle ${LANG_ENGLISH} "Destination Folder"
LangString mydirsubtitle ${LANG_ENGLISH} "Click Next to install to the default folder or click Browse to choose another"
I found the root cause of not displaying the UI in other language (for eg, French). It is because i didn't include the language specific folder (for eg, "fr" that has resources.dll) in "INSTDIR".
To include that I have written the below lines of code and it is working now:
SetOutPath $INSTDIR\fr
File /a /r "C:\Code\EMR\bin\x86\Release\fr\"

How to show the Systray Icon and also the corresponding executable in the taskmanager by default when we run the installer using NSIS?

My requirement is: When i installed a software using NSIS, once the installation is successfully completed it should show a notification icon (systray icon).
I am able to create the installer with the required dlls, executables and other files. But it is not showing the systray icon automatically.
Use ExecShell, Exec or ExecWait to start a new process:
Section
SetOutPath $INSTDIR
File "something\Display.exe"
ExecShell "" "$INSTDIR\Display.exe"
SectionEnd
If you are using the Modern UI then you can put a run checkbox on the finish page instead if you want to give the user the option of not running the app:
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\Display.exe"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section
SetOutPath $INSTDIR
File "something\Display.exe"
SectionEnd

Run application after install(silent installer)

I want to run my application immediately after install and I understand the code to do it is as follows:
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH
Section
CreateShortcut "$DESKTOP\HelloWorldShortcut.lnk" "$INSTDIR\Hello World.exe" "dev03 3"
SectionEnd
Function LaunchLink
ExecShell "" "$DESKTOP\HelloWorldShortcut.lnk"
FunctionEnd
The problem is my installer is a silent installer but the above code adds a page to it.
Is there a way to use a silent installer to also run the application immediately after install?
A silent installer can just run the app as the final step in the last section. Whether or not it is a good idea for a silent installer to start the application is something you should think about, personally I would say no...
Section
SetOutPath $InstDir
File "MyApp.exe"
...
IfSilent "" +2 ; If the installer is always silent then you don't need this check
ExecShell "" "$InstDir\MyApp.exe"
SectionEnd

NSIS Installer based on zip?

Does anyone have a basic NSIS script example that is "installer based on zip"? Or could tell me the command? I know NSIS has that tool built in, but I want to edit a script based on that. NSIS only outputs an .exe of the installer based on zip. I would like to start from script code.
Thanks.
The zip2exe tool generates a simple script that it passes to makensis, most of the code is in files it includes:
!define ZIP2EXE_COMPRESSOR_ZLIB
!define ZIP2EXE_INSTALLDIR "c:\foo"
!include "${NSISDIR}\Contrib\zip2exe\Base.nsh" ; You could edit this if you wanted to keep using zip2exe
!include "${NSISDIR}\Contrib\zip2exe\Classic.nsh"
!insertmacro SECTION_BEGIN
File "file1fromzip.txt"
File "file2fromzip.exe"
!insertmacro SECTION_END
you can use the following script to extract the zip files in the destination location and before you compile this script you need to download the ZipDLL.dll place it in your NSIS installation folder.
OutFile "Zip.exe"
section
ZipDLL::extractall "C:\Users\raj\Desktop\envConfig.zip" "C:\Program Files (x86)\Zip"
sectionend
To build on Anders answer, a few additional things should be done in the latest version. In particular ZIP2EXE_NAME and ZIP2EXE_OUTFILE should be set:
!define ZIP2EXE_COMPRESSOR_ZLIB
!define ZIP2EXE_INSTALLDIR "c:\foo"
!define ZIP2EXE_NAME "My Application"
!define ZIP2EXE_OUTFILE "MyInstaller.exe"
!include "${NSISDIR}\Contrib\zip2exe\Base.nsh"
!include "${NSISDIR}\Contrib\zip2exe\Classic.nsh"
!insertmacro SECTION_BEGIN
File "file1fromzip.txt"
File "file2fromzip.exe"
!insertmacro SECTION_END
Classic.nsh can be replaced with Modern.nsh for the "Modern" UI.
Also note that either the files need to be enumerated in the "File" section, or if you have your files in a folder, you can include the entire contents:
File /r MyFolder\*.*
This will NOT create "MyFolder" inside the install target directory.

Resources