Archive: Passing a parameter to the .nsi file


Passing a parameter to the .exe file
Hello,

I developped an NSIS installer who works.

But now I would like to modify its reaction when it is called with different parameters.

For exemple "my_intaller.exe /P parameter" (where /P significate that the parameter exists and parameter is its value) will allow the installer to know that it has a page to show that it doesn't show if the parameter doesn't exist.

I really don't know how to control if this parameter exists or not and how to read its value(s) (there can be many), could you please help me, it is very important and urgent.

Thank you very much.


Have you tried googling for 'parameter NSIS'?


Sure I did it, but I can't find a suitable answer to my case, I don't know how to read if there is a parameter and it's value. I found solutions to compile a new .exe with parameters but it is not that I want to do.


I found this kind of answer but I don't understand what is the variable $CMDLINE and how it is passed and to read it. The description of this Funtion says "This function gets all parameters given to the installer on the command-line."


; GetParameters
; input, none
; output, top of stack (replaces, with e.g. whatever)
; modifies no other variables.

Function GetParameters

Push $R0
Push $R1
Push $R2
Push $R3

StrCpy $R2 1
StrLen $R3 $CMDLINE

;Check for quote or space
StrCpy $R0 $CMDLINE $R2
StrCmp $R0 '"' 0 +3
StrCpy $R1 '"'
Goto loop
StrCpy $R1 " "

loop:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 $R1 get
StrCmp $R2 $R3 get
Goto loop

get:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 " " get
StrCpy $R0 $CMDLINE "" $R2

Pop $R3
Pop $R2
Pop $R1
Exch $R0

FunctionEnd


Is it possible to show the license page just when there is a parameter add to the .exe file ?

Someone could tell me how to do, because the '!insertmacro MUI_PAGE_LICENSE "license.rtf"' line can't be add in a function and the function "${If} ..." has to be include in a function, how to do ???


I found this post who seems to convain perfectly to my problem

forums.winamp.com/showthread.php?postid=2211896

but I don't uderstand how to modify the third part named parseParameters function to adapt it to my case. For exemple I need to show the license page IF there is a parameter and only in this case.


Use the license page Pre function to call 'abort' unless the parameter was supplied. Abort in a pre function will skip the page.


Use GetParameters and GetOptions from the manual.

Stu


What is the Pre Function ?

I have now :

!insertmacro MUI_PAGE_WELCOME
!insertmacro GetParameters
!insertmacro GetOptions
!include "pages\licenseshow.nsh"

... in my .nsi file but the license page appears before the welcome one.

Does someone have a explanation ?