NSIS scripting file error while extracting a zip file - nsis

When I am using the following NSIS script:
ZipDLL::extractall "C:\Users\sid008\Desktop\NSISTutorials.zip" "F:\nist" "<ALL>"
then I am getting the below error:
!define: "MUI_INSERT_NSISCONF"=""
Changing directory to: "C:\Users\sid008\Desktop"
Processing script file: "C:\Users\sid008\Desktop\Ext1.nsi" (ACP)Error: Can't add entry, no section or function is open!
Error in script "C:\Users\sid008\Desktop\Ext1.nsi" on line 1 -- aborting creation process
Any ideas on what goes wrong?

As the error says: You need to use this line inside Function or Section.
The correct usage:
Section "Section name"
ZipDLL::extractall "C:\Users\sid008\Desktop\NSISTutorials.zip" "F:\nist" "<ALL>"
SectionEnd
Function Func
ZipDLL::extractall "C:\Users\sid008\Desktop\NSISTutorials.zip" "F:\nist" "<ALL>"
FunctionEnd

Related

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.

Error when trying to use File inside ${ForEachIn}?

I have the following code block inside the .onInit function of my NSIS script.
; Split the supplied artifacts array.
nsArray::Split ARTIFACT_ARRAY "${ARTIFACTS}" ";"
${ForEachIn} ARTIFACT_ARRAY $R0 $R1
File ${IVY_ROOT}\"$R1"
${Next}
The ${ARTIFACTS} is a passed in property from ANT at NSIS compile time and is basically a comma seperated list of files. When I attempt to compile the script I get the error below.
[exec] File: "C:\My_Workspaces\WEnDL\\deployments\ivy\"$R1"" -> no files found.
[exec] Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
[exec] /oname=outfile one_file_only)
[exec] Error in script "C:\My_Workspaces\WEnDL\/deployments/selections.nsis" on line 394 -- aborting creation process
Any pointers appreciated.
You cannot use variables in File instructions because variables are only evaluated on the end-users system. The same is true for plug-ins. You need to stick with ${defines} and the instructions starting with ! when parsing at compile-time.
The best option is letting your build system generate a .nsh with the File instructions if possible:
Section
SetOutPath $InstDir
!include "generatedfilelist.nsh"
SectionEnd
Another option is to call external tools or batch-files with !system and let them parse the list and generate the .nsh.
Finally, in NSIS v3 it might be possible to pull this off with macro recursion and !searchparse+!searchreplace but the available recursion depth is limited so it might not work depending on the number of files in your list.

NSIS Invalid command: IDOK/IDCANCEL

I am able to use MessageBox MB_OK and MB_OKCANCEL, but compiler throws an error when I try to use IDOK and IDCANCEL.
My NSIS version is 2.46.
The basic syntax for calling MessageBox with OK and Cancel buttons is:
MessageBox MB_OKCANCEL "my message" IDOK label_for_ok IDCANCEL label_for_cancel
label_for_ok:
;do some stuff
goto end_label ;for not executing the "cancel" branch
label_for_cancel:
;do some other stuff
end_label:
In this case, as the ok case is just after the Messagebox, you can remove the IDOK label_for_ok and the label at the following line.
(Sorry for this little self promo)
You can use my tool called Visual & Installer (http://www.unsigned-softworks.sk/visual-installer/) to check correct syntax and usage in NSIS script in Visual Studio to avoid such situations:
As you can see it has a really nice syntax highlighting, when you move over some command a tooltip is shown and (if you look at Error List) you can see the PROGRAM_NAME was recognized as unused because it was not defined in the script snippet.

How to modify text value in Bat file using Nsis script

I have builded Nsis script successfully.I have bat file in my project.Inside bat file i have two variables with default values as follows
JVM_DLL=c:\program Files\java\jre\bin\client\jvm.dll
Home_path=c:\opt\projectName
If the user wants to modify the value for JVM_DLL and Home_path that should be written in batch file.How to do this? I donot know how to write in batch file using Nsis script?
I have tried following codes.but its not working
StrCpy $JVM_DLL "jre\bin\client\jvm.dll"
${ConfigWrite} "$INSTDIR\resource\batch.bat" "JVM_DLL" "=$JVM_DLL" $R0
${ConfigWrite} "$INSTDIR\resource\batch.bat" "HOME_PATH" "=$INSTDIR" $R0
thanks
If you have defined the 2 values in the .bat file that is also launching makensis.exe, use the /D command line switch to define those values for the nsis script.
In your example, given your 2 .bat variables:
makensis.exe /DJVM_DLL=%JVM_DLL% /DHome_path=%Home_path% yourscript.nsi

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