So I embedded two installers into my install script created with nsis, the whole thing is supposed to install one program then the other one, and then overwrite three files created by the second installer with newer versions. The problem is that those three files get created before the second installer gets to work. How can I make sure that these files get created only after the second installer finish it's job?
`
!include "MUI2.nsh"
; The name of the installer
Name "ADIS"
RequestExecutionLevel user
; The file to write
OutFile "ADIS.exe"
Unicode true
; The default installation directory
InstallDir "C:\ADIS"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "Spanish"
;--------------------------------
; The stuff to install
Section ""
; Set output path to the installation directory.
SetOutPath $INSTDIR
RMDir /r $INSTDIR
SectionEnd
SectionGroup "instaladores"
Section "Firebird"
ExecWait "Firebird\Firebird-2.5.4.26856_0_Win32.exe"
SectionEnd
Section "Cliente"a
ExecWait "Cliente\setup.exe"
SectionEnd
SectionGroupEnd
Section "Actualiza"
; Put file there
;File Nvo\ADIS.exe
;File Nvo\ADIS.ICO
;File Nvo\ADIS.GDB
File /r "Nvo\*"
SectionEnd`
You should probably run "Cliente\setup.exe" silently. Most installers have a silent switch you can use on the command line and some also provide a wait switch so you can wait even if the installer uses child processes.
What happens if you add a MessageBox before the file command and don't click it until the other installers have completed?
Related
I have the following code snippet used to write the registry files to the path :
;Registry and SDK Setup
Section "mySection"
SetOverwrite on
SetOutPath "C:\ProgramData\....\Gadgets"
File "{....KEYS...}.png"
File "{....KEYS...}.xml"
WriteRegStr HKLM "...\STC\Gadgets\{....KEYS...}" "toastAction""DisableToast"
SectionEnd
The above code fails to write the registry files. Could someone help me find the issue?
You need to set the $INSTDIR variable to indicate the destination directory. MUI 2 has a ready made page to let the user choose the destination folder. It's called MUI_PAGE_DIRECTORY:
!include "MUI2.nsh"
Name "Test"
Outfile "test.exe"
InstallDir "$LOCALAPPDATA\test"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
SetOutPath "$INSTDIR"
;Use File to copy files to destination folder.
SectionEnd
I have installer, which supports choosing installation directory. And I want to detect if given folder exists and if it is empty. If it is NOT empty, show warning message box, then remove all its contents and install program into that folder. Only problem is to get into the right code section, where I can get installation folder given by user during installation, I can handle the rest.
Thank you for any advices.
Normally you would just check if the directory exists:
Outfile "$%Temp%\Test.exe"
RequestExecutionLevel user
InstallDir "$Documents\Test"
!include LogicLib.nsh
Page Directory "" "" DirLeave
Page InstFiles
Function DirLeave
${If} ${FileExists} "$InstDir\*"
MessageBox MB_YESNO `"$InstDir" already exists, delete it's content and continue installing?` IDYES yep
Abort
yep:
RMDir /r "$InstDir"
${EndIf}
FunctionEnd
Section
SetOutPath $InstDir
File myfile.ext
SectionEnd
This will also display the message if the directory exists but is empty. To work around that you would need some custom detection:
!macro _IsNonEmptyDirectory _a _b _t _f
!insertmacro _LOGICLIB_TEMP
!insertmacro _IncreaseCounter
Push $0
FindFirst $0 $_LOGICLIB_TEMP "${_b}\*"
_IsNonEmptyDirectory_loop${LOGICLIB_COUNTER}:
StrCmp "" $_LOGICLIB_TEMP _IsNonEmptyDirectory_done${LOGICLIB_COUNTER}
StrCmp "." $_LOGICLIB_TEMP +2
StrCmp ".." $_LOGICLIB_TEMP 0 _IsNonEmptyDirectory_done${LOGICLIB_COUNTER}
FindNext $0 $_LOGICLIB_TEMP
Goto _IsNonEmptyDirectory_loop${LOGICLIB_COUNTER}
_IsNonEmptyDirectory_done${LOGICLIB_COUNTER}:
FindClose $0
Pop $0
!insertmacro _!= "" $_LOGICLIB_TEMP `${_t}` `${_f}`
!macroend
!define IsNonEmptyDirectory `"" IsNonEmptyDirectory`
Function DirLeave
${If} ${IsNonEmptyDirectory} "$InstDir"
MessageBox MB_YESNO `"$InstDir" already exists, delete it's content and continue installing?` IDYES yep
Abort
yep:
RMDir /r "$InstDir"
${EndIf}
FunctionEnd
I need to change the text on the "Choose Install Location" page of an NSIS installer to say that my program can not be installed in a directory containing spaces in the name.
What is the best way to change this text?
!include MUI2.nsh
!define MUI_PAGE_HEADER_TEXT Foo
!define MUI_PAGE_HEADER_SUBTEXT Bar
!define MUI_DIRECTORYPAGE_TEXT_TOP Baz
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION Bob
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
You might also want to check the path when the user is about to leave the page (In the page leave callback)...
I'm having a weird error with NSIS:
!include "MUI2.nsh"
!include "FileFunc.nsh" # To use GetParameters
Name nsDialogs
OutFile nsDialogs.exe
Function .onInit
${GetParameters} $R0
MessageBox MB_OK "$R0"
FunctionEnd
!insertmacro MUI_PAGE_WELCOME
Section
DetailPrint "hello world"
SectionEnd
If I use this command line
nsDialogs.exe /d=hello
the message box says: "/d=hello" as expected, but if I use
nsDialogs.exe /D=hello
the message box says "" and this is wrong.
Why is this happening?
From the documentation:
/D sets the default installation directory ($INSTDIR), overriding
InstallDir and InstallDirRegKey. It must be the last parameter used in
the command line and must not contain any quotes, even if the path
contains spaces. Only absolute paths are supported.
This means you cannot use /D with ${GetParameters} (/S and /NCRC are also switches used by NSIS). NSIS by design uses everything after /D= as $instdir.
The only way to detect /D is to not use InstallDir[RegKey] in your script and check if $instdir is != "" in .onInit
/D is command line parameter that let define the installation directory directly from the installer command line invocation.
See the Installer usage / Common Options chapter for details.
I don't know for sure, but I assume that NSIS strips out its inbuilt parameters by default. In that case you could try something like this:
!define myInstDir "$PROGRAMFILES\myApp"
Function .onInit
${GetParameters} $R0
StrCpy $R0 ${myInstDir} +2
MessageBox MB_OK "$$INSTDIR was changed on runtime"
FunctionEnd
I want to add a label displaying the full version-string in the welcome screen in the installer I am creating using NSIS with MUI2.
I have searched for info on how to do this, but only found references to using MUI_INSTALLOPTIONS* which I found ws deprecated for MUI2. Another one referred to the newer versions using INSTALLOPTIONS* with the same options, but I could not get it working. I finally also found a reference to using nsDialogs for this - which is what I am using for my custom pages. However - I found no reference or samples on how to change any of the existing pages that comes with MUI2.nsh.
I found a way to change the MUI_HEADERTEXT, but that doesn't affect the welcome-screen. I wish there was a way to also change the welcometext. Maybe using MUI_WELCOMETITLE and MUI_WELCOMEBODY or similar.
There is MUI_WELCOMEPAGE_TEXT but it is only useful if you want to change all of the text and not just append something.
During the show function for the page, you can change the text of any control:
outfile test.exe
requestexecutionlevel user
!include MUI2.nsh
#!define MUI_WELCOMEPAGE_TEXT "New text goes here"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function MyWelcomeShowCallback
SendMessage $mui.WelcomePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_WELCOME_INFO_TEXT)$\n$\nVersion: foo.bar"
FunctionEnd
Section
SectionEnd
..or add a new control:
outfile test.exe
requestexecutionlevel user
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function MyWelcomeShowCallback
${NSD_CreateLabel} 120u 150u 50% 12u "Version: foo.bar"
Pop $0
SetCtlColors $0 "" "${MUI_BGCOLOR}"
FunctionEnd
Section
SectionEnd
I also had the issue with NSIS. In my case it worked to define MUI_WELCOMEPAGE_TITLE before inserting the macro MUI_PAGE_WELCOME.
It should look like:
!define MUI_WELCOMEPAGE_TITLE "CUSTOM TITLE HERE"
!insertmacro MUI_PAGE_WELCOME