Search code examples
powershellbatch-fileparameter-passingnsissilent-installer

Windows silent installation with file parameter


I'm trying to make a silent installation through a Windows Batch script with a file parameter, but I'm not being able to do it. I have a file (params.txt) which contains the parameters that should be input during the installation (such as path, choices etc).

Obs.: It may also be by PowerShell.

I have something similar in Linux, which is pretty easy:

.../installer.sh < .../params.txt

But I'm trying in many different ways, with NSIS, MSI. But none of them seens to solve my problem with these parameters. The closest that I've got was

C:\installer.exe /S

indeed its make the installation with the default parameters, but I would like to specify them through my file.

I've made many researches, even here in stackoverflow, but nothing that solves my problem.

Content of my params.txt file:

yes
no
C:\Software\MySoftware
yes
no
no
no

The installation prompts a few questions, and the file contains the answers that I need to give during the installation.

Also, the installer was generated using NSIS (Nullsoft Scriptable Install System) .

Thank you in advance.


Solution

  • NSIS supports the /S and /D=c:\installpath parameters by default, support for anything else has to be provided by the install author.

    Install authors can check for specific parameters and/or a answer file:

    !include FileFunc.nsh
    !include LogicLib.nsh
    
    Section
    
    ; Command-line parameter:
    ${GetParameters} $0
    ClearErrors
    ${GetOptions} $0 "/Something" $1
    ${IfNot} ${Errors}
        ; Do Something
    ${Else}
        ; Do something else?
    ${EndIf}
    
    ; Answer .INI file:
    Var /Global AnswerFile
    StrCpy $AnswerFile $ExePath -4
    StrCpy $AnswerFile "$AnswerFile.ini"
    ReadIniStr $0 $AnswerFile "Options" "OtherPath"
    ${If} $0 != ""
      File "/oname=$0\file.ext" "c:\mysource\fileForOtherPath.ext"
    ${EndIf}
    
    SectionEnd