Passing more than one parameter to another nsi - nsis

I have an installer I inherited, and I need to pass 2 parameters to another *.nsi on install. Currently it works fine with one param, which is just a string:
ExecShell "" '"$TEMP\Setup.exe"' "Param1"
This gets read as so, from the other side:
${GetParameters} $commandLineParam
The second param is a variable ($version) that needs to be sent over:
StrCpy $version "1.1.1.0"
Just adding an additional "Param2" doesn't build
Error 13 error MSB3721: The command ""C:\Program Files (x86)\NSIS\Unicode\makensis" ... exited with code 1.
I'm sure I'm missing something syntax-wise.

MakeNSIS removes the outer-most set of quotes when it parses the .NSI file.
StrCpy $0 "blah"
StrCpy $1 '"baz"'
ExecShell "" "c:\foo\bar.exe" 'p1 "Hello World" p3 $0 $1'
will run c:\foo\bar.exe with p1 "Hello World" p3 blah "baz" as the parameters.

Related

NSIS: Despite preproccsor get warning unknown variable/constant "test" detected

I use only use some code if the Flag is set. So I got the warning
Variable "test" not referenced or never set, wasting memory!
so I use the preprocessor commands
!if ${Flag} == 1
Var test
!endif
But I still get a warning
unknown variable/constant "test" detected, ignoring (macro:_==:1)
So why do I still get a warning and how could I disable the warning:
Maybe I could use !pragma to disable the warning. But this works only for nsis3. What could I do at nsis2?
You most likely messed up your !if guards around $test.
!define Flag 1
!if ${Flag} == 1
Var test
!endif
will print Variable "test" not referenced or never set, wasting memory! if you never access $test in a Section/Function.
On the other hand
Section
${If} $test == "something"
${EndIf}
SectionEnd
will print unknown variable/constant "test" detected, ignoring (macro:_==:1) if the code does not do Var test first.
And finally
Var test
Section
${If} $test == "something"
${EndIf}
SectionEnd
will also print Variable "test" not referenced or never set, wasting memory! for some reason but the warning goes away if you actually assign something to $test somewhere in your code:
Var test
Function .onInit
StrCpy $test ""
FunctionEnd
Section
${If} $test == "something"
${EndIf}
SectionEnd

NSIS variable value get set concerns

Well, from few years I'm working with NSIS installers and I treat all variables as string in my scripts. Somewhere I read about this, that NSIS internally treat all variables as string, but don't know the exact fact.
Now my query is whenever we are copying some values into some variables or checking the variable's value using logic statements what should be the ideal way to do it. Let me show you an example what I'm talking about.
StrCpy $1 "Some string goes here"
StrCpy $2 999
${If} $1 == "String to match here"
${If} $2 == 999
${If} $2 == "999"
I guess I have no other option for StrCpy $1 case as there I'm copying string into a variable, but for case StrCpy $2, perhaps I can write StrCpy $2 "999" as well. Same thing goes for If statements.
I would like to know the correct convention for NSIS scripting.
Yes, internally everything is stored as strings and they converted to numbers when doing a number operation. Strings that cannot be converted to numbers are treated as 0.
StrCpy $2 999 and StrCpy $2 "999" is exactly the same thing, the quotes are only required when the string has spaces and the quotes are removed by the compiler automatically even when there are no spaces. This also means that ${If} $2 == 999 and ${If} $2 == "999" is the same.
When comparing you should use =, <>, <, <=, >= and > for numbers and == and != for strings.
${IfThen} 0x29A = 666 ${|} DetailPrint "True" ${|} ; 0x29A is 666 in hex
${IfThen} 0x29A == 666 ${|} DetailPrint "This will never print" ${|}

NSIS exec JScript with parameters

I'm trying to run a JScript that receives a parameter (like a cmd argument).
Consider the following JScript:
myScript.js:
var args = WScript.Arguments; //get cmd args
WScript.Echo(args[0]); //output the first argument gotten from NSIS
I'm trying to do so with the following NSIS script:
installer.nsi:
Var /GLOBAL argumentToSendForJScript
StrCpy argumentToSendForJScript "helloFromNSIS"
File 'runme.js'
Exec "wscript.exe C:\myScript.js $argumentToSendForJScript"
Problem is, the argument isn't arriving the JScript. I suspect that it is due to the fact the argument is arriving to wscript.exe instead of myScript.js, because it works if I execute the script directly from a windows command prompt instead of NSIS, like so:
myScript.js helloFromCMD
Any ideas how this could be achieved?
WScript.Arguments is not a normal javascript array, you must access the items with (123), not [123].
Section
; Create a dummy script:
InitPluginsDir
FileOpen $0 "$PluginsDir\test.js" w
FileWrite $0 "var args = WScript.Arguments;$\n"
FileWrite $0 "WScript.Echo('length='+args.length, args(0));$\n"
FileClose $0
Var /GLOBAL argumentToSendForJScript
StrCpy $argumentToSendForJScript "helloFromNSIS"
ExecWait '"WScript.exe" "$PluginsDir\test.js" $argumentToSendForJScript'
SectionEnd

NSIS substring by index

Is there any function which can cut string by letter index? I mean the X letters from the end?
!define myString "abcdefg"
I need to get for ex. "efg"
i tried to do that with nsis strings functions but didnt found what can help me.
${StrStr} and all the other functions doesnt do the work
Thanks
This is very simple. Actually, you don't have any dedicated function to do that, but you StrCpy can do that with 3rd and 4th arguments.
The format is going like that:
user_var(destination) str [maxlen] [start_offset]
And the usage for you case, is:
StrCpy $0 $myString "" -3
$0 will be: efg
More information about StrCpy function, can be found out there: http://nsis.sourceforge.net/Reference/StrCpy
StrCpy $0 "abcdefg" "" -3 ; variable $0 now has the last 3 letters
See the manual for more info about StrCpy

NSIS Function with more than 1 parameters

Can a NSIS Function have more than one parameter?
Why wont this code compile? If I cant have more than 1 param for a function what are my other options(disregarding using a macro)?
Compile error:
Function expects 1 parameters, got 4. Usage: Function function_name
Outfile "test.exe"
Caption ""
Name ""
# Compile Error Here: "Function expects 1 parameters, got 4. Usage: Function function_name"
Function MyFunction p1 p2 p3
DetailPrint "$p1, $p2, $p3"
FunctionEnd
Section
DetailPrint "Hello World"
SectionEnd
You have to pass parameters in registers and/or on the stack:
Function onstack
pop $0
detailprint $0
FunctionEnd
Function reg0
detailprint $0
FunctionEnd
Section
push "Hello"
call onstack
strcpy $0 "World"
call reg0
SectionEnd

Resources