Archive: Need to add switches to installer


Need to add switches to installer
  I need to add a switch to an installer that will write a DIFFERENT INI setting instead of the normal one, using MUI.. How do I go about doing this? If it is easier to use InstallOptions to figure this out, then by all means do that!
The switch I want is "--user"
Code by default:

WriteINIStr "$INSTDIR\\overrwdef.ini" "System" "OverWrite" "0 ; If enabled Program will use overwrite profile settings when run" 

Code I want optional:
WriteINIStr "$INSTDIR\\overrwdef.ini" "System" "OverWrite" "1 ; If enabled Program will use overwrite profile settings when run" 

The code is in a section during file installation process, if you want to give InstallOptions thing, then it should be able to change within the section...

Sorry I don't have time to create a better working example, but if I understood you correctly, something like this should get you started:

1. First, define a variable (such as PARAMETER) in the first part of your script. Then, in the first line of your .onInit function, set it's value to zero.

2. In Appendix E (Useful headers), you'll find two functions: GetOptions and GetParameters. Use one or both to read the paramater and then set $PARAMETER to 1 if "--user" is found as a parameter.

3. Finally, check the value of $PARAMETER during your installation to decide what 'branch' of code you want to execute.

Using your optional INI settings from above as an example:


StrCmp $PARAMETER 1 JumpIfSet JumpIfNotSet

JumpIfSet:
WriteINIStr "$INSTDIR\overrwdef.ini" "System" "OverWrite" "1"
Goto JumpIfNotSet

JumpIfNotSet:
; continue your code here


Let me restate it: I want the perameter to be set by a switch.

WriteINIStr "$INSTDIR\\overrwdef.ini" "System" "OverWrite" "$PERAMETER ; If enabled Program will use overwrite profile settings when run" 

If --user is given in commandline, the $PERAMETER should be set to "1". Otherwise, it should be set to "0". I hope this helps... The solution given doesn't work in my script...

So what I understand is that you want to set a parameter depending on whether the '--user' switch is used or not. If so, use GetParameters described above, and do a strcmp on the result. This code should either be in a function or in a section.


;The getparameters function here and put the result in $0

StrCmp $0 "--user" +1 DontOverwrite
WriteINIStr "$INSTDIR\overrwdef.ini" "System" "OverWrite" "1"
GoTo skip
DontOverwrite:
WriteINIStr "$INSTDIR\overrwdef.ini" "System" "OverWrite" "0"
skip:
;the rest of code here

Originally posted by JasonFriday13
So what I understand is that you want to set a parameter depending on whether the '--user' switch is used or not. If so, use GetParameters described above, and do a strcmp on the result. This code should either be in a function or in a section.

;The getparameters function here and put the result in $0

StrCmp $0 "--user" +1 DontOverwrite
WriteINIStr "$INSTDIR\overrwdef.ini" "System" "OverWrite" "1"
GoTo skip
DontOverwrite:
WriteINIStr "$INSTDIR\overrwdef.ini" "System" "OverWrite" "0"
skip:
;the rest of code here
How do I set the GetPeraters function, I'm using:

0 

>
When I use it before the INI settings, it saying the GetPerameters is invalid?

Did you use the following at the top of your script?

!insertmacro GetParameters
See the documentation for more information.

Originally posted by kichik
Did you use the following at the top of your script?
!insertmacro GetParameters
See the documentation for more information.
Yeah, it says invalid macro!

Read the docs:
You need to make sure you include the header file.

From the docs:

Include header:
!include "FileFunc.nsh"
And make sure you are using the latest build of NSIS. The extra header files used for this function were not included until version 2.08 and some functions may have had a few updates/fixes since then.

I did, and I am using NSIS v2.15!


Alright then, post the script as an attachment, and we can tell you where you went wrong.


Alright, here is a script with all the parts in it...


Check your spelling:

!insertmacro GetParameters

Was: !insertmacro GetPerameters

Changed it and it still was invalid! Is there a way to do this in a dialog instead? As in a dialog before the file transfer page...


I have fixed the script and attached it. I commented out all the stuff that was not needed for the script just so you could see that it does work. The only thing the installer does now is write the ini to the desktop. At the command prompt type: setup.exe --user and you will get an ini file with 1 in it instead of 0.


This looks like the EXACT same script as the one I attached earlier... Even my spelling error of GetPerameters is still there...


Alright then, just to prove it, I have uploaded a zip with the script and the .exe produced by it.


Alright, it is working! Thank you all...


Pharaoh Atem, sounds like your internet cache needs clearing out. I suspect you're using IE?

-Stu


I was, I accidently used IE to view it last time... I switched to Firefox and saw the changes... Thanks


Thats what I like to hear.