Exec not working in NSIS installer - nsis

I am new to NSIS i am trying to execute an executable while installation similar to pre request. I tried the below code which copies the exe to the installation path but it is not executing it.
Section "example" example
SetOutPath "$INSTDIR"
File "setup.exe"
Exec "$INSTDIR\setup.exe"
BringToFront
SectionEnd

The answer from Seki is mostly correct, I'd just like to add that the correct syntax for Exec/ExecWait is always Exec '"c:\path\app.exe" param1 "par am2" param3'
Parameters are of course optional but the path to the app should always be quoted, not just because in your case where $INSTDIR could contain spaces but at least on Win9x it will fail no matter what if you don't quote (According to the NSIS manual)
If the spaces/lack of quotes is not the issue then there are a couple of other things you might want to look into:
$OUTDIR is the working directory for the new process (SetOutPath sets this)
Missing dll's etc (Check with Process Monitor)

Do the $INSTDIR variable maps to a directory whose name contains spaces? If so, you should add simple quotes to include the double quotes into the Execargument :
Exec '"$INSTDIR\setup.exe"'

Related

Fail to copying file in NSIS?

For copy file i use (code below) its work properly.
Section "one"
CreateDirectory $EXEDIR\dst
CopyFiles $EXEDIR\*.* $EXEDIR/dst
SectionEnd
When i use $PROGRAMFILES(only change the destination path) it create directory but copy doesn't work.
Section "two"
CreateDirectory $PROGRAMFILES\dst
CopyFiles $EXEDIR\*.* $PROGRAMFILES/dst
SectionEnd
where is the problem?
/ is not the path separator on Windows, use \. / is supported in a lot of places but not everywhere.
It might also be failing if you don't have write access to that folder so make sure you have RequestExectionLevel Admin in your script.
The only way to know for sure is to monitor the installer with Process Monitor...

Where can I add command line in the NSIS script

I would add some command line to customize my NSIS intaller. I already read some topics, I know I must use ${GetParameters} and ${GetOptions}. But the NSIS script is very long do I put him somewhere in the OnInit function or in a section at the beginning of the script ?
I want, for example, to add an --quiet command line which display all the pages except the license( something which seems to /S), I want to try something like that:
Var DisplayAllPages
Var DisplayLicense
${GetParameters} "quiet"
${GetOptions} "quiet" "--quiet"=DisplayLicense
But I don't Know where can I write
You can use ${GetParameters} and ${GetOptions} in any function and/or section.
Only .onInit and sections are executed when the installer is started with /S so if you wish to turn silent mode off you need to put the code in .onInit.
If you are storing the result in a global variable then .onInit is also a good place to call them so that the information is available to the rest of the installer.

How to add a default folder always with target installation using NSIS

I want to append a default directory to my INSTALL directory always internally.
I have set it by default but if user change the directory then it not works and installed the files in the folder that user selected.
So I need append a folder ( Product name ) always internally and it can be append with the user's selected path.
Like if user selected "C:\Program Files\My Folder" then the installation should be in path "C:\Program Files\My Folder\ProductName"
Should work with the silent as well.
Can someone please advise on this.
Section MyFirstSection
StrCpy $InstDir "$InstDir\ProductName" ; Force extra sub-directory
; ...
SectionEnd
However, the recommended way to do this is to just use InstallDir without a ending backslash:
Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a \ (which will require the entire parameter to be enclosed with quotes).

check for file existence using nmake and delete it

I am using Windows version of NMAKE. I would like to check for file existence in a make file. If it exists I need to delete it. Here is my code:
!IF EXIST ("C:\ABC.XML")
#del ABC.XML
!ELSE
#echo "FILE DOESN'T EXIST
!ENDIF
The above code is not working. I could not figure it out the problem. Please help.
Your code doesn't work because !IF, !ELSE and !ENDIF are a preprocessing directives and the result of preprocessing must produce a valid makefile. Commands are only allowed as part of what Microsoft calls a description block which are required to start with a dependency line with one or more targets and zero or more dependents.
You can get around this by executing your commands during the preprocessing stage by including them in a preprocessing directive surrounded by brackets ([]). Something like this:
!IF EXIST(C:\ABC.XML)
! IF [del C:\ABC.XML]
! ENDIF
!ELSEIF [echo FILE DOESN'T EXIST]
!ENDIF
The second !IF and the !ELSEIF directives are used to provide a context for the commands so they're executed during the preprocessing phase.
However I think you'd probably be better moving the del command to a description block where it's actually needed. For example if file ABC.XML needs to be deleted before it can be rebuilt, use something like this:
ABC.XML: ABC.CSV
-rem The csv2xml translator requires that the XML file not already exist
-#del ABC.XML 2> NUL
csv2xml ABC.CSV ABC.XML

Accessing command line arguments in NSIS

I am trying to make my setups scripts modular. I am calling setup exe's from within main setup script based to the requirements. I want to pass command line arguments to the exe being called. Can someone please tell me how to access the command line arguments in the script being called.
Thanks in advance.
you can use GetOptions function (FileFunc.nsh must be included above). Following example shows p parameter reading; its value is saved into the variable. $CMDLINE is your command line (absolute or relative, as you called) containing also your parameters.
!include FileFunc.nsh
Var variable
${GetOptions} $CMDLINE "/p" $variable
Try to get options from Command line by their name:
http://nsis.sourceforge.net/Get_command_line_parameter_by_name

Resources