Search code examples
installationcommand-line-argumentsnsis

Trying to add command-line argument execution to NSIS installer


I am trying to customize the NSIS installer. Based on an option from the user, I would like the program to run with a different option, which I would set up with a command line option.

(I save some files that I delete at the end, and if the user doesn't want to proceed with the install, then I want to run the utility with the option -d that only deletes temporary files.)

I have found this post: Accessing command line arguments in NSIS but I don't know how to set it up to run a program with a command-line argument.

This is what I am trying: I tried:

SetOutPath "$TEMP"
!define MY_FILE "file.exe -d"
File /nonfatal "${MY_FILE}"
ExecWait '"$TEMP\${MY_FILE}" 
Delete /REBOOTOK "$TEMP\${MY_FILE}"

I got a warning that it didn't find file.exe -d.

So I am trying something like

$(GetOptions) $CMDLINE "/d" $Trying_This
;Not sure what to put to get the program

I am still experimenting with NSIS, it is a huge challenge, and can't find an example to guide me.

Note: I am running the file with no options, and then I want NSIS to insert the option -d (or other options like -f filename)

Edit: I had incomplete code in the post... I had the ExecWait in real life...


Solution

  • Outfile test.exe
    requestexecutionlevel user
    InstallDir "$Temp\Test" ;Default $InstDir
    !include FileFunc.nsh
    !include LogicLib.nsh
    
    page directory
    page instfiles
    
    section 
    StrCpy $1 "/Foo"
    ClearErrors
    ${GetOptions} $CMDLINE "-d" $0
    ${IfNot} ${Errors} 
        StrCpy $1 "/Bar"
    ${EndIF}
    SetOutPath $InstDir
    File "File.exe" ;Extracting to $InstDir
    ExecWait '"$InstDir\File.exe" $1' ;Calling with /Foo or if installer was started with -d; /Bar 
    sectionend