user2435588
user2435588

Reputation: 11

NSIS silent installer path overriding

I'm running my program installer done with NSIS but the /D option seems not working (or better overridden inside). Via command line I trigger:

installer.exe /S /D=C:\Users\Public\installDir

NSIS code is:

InstallDir "C:\Users\Public\${VERSIONSTR}"


Function xxxx
 ${If} $MultiUser.InstallMode == "AllUsers"      
 StrCpy $INSTDIR "C:\Users\Public\Dir1"
 ${EndIf}
 IfSilent 0 +20
   StrCpy $INSTDIR "C:\Userdata\Dir2"
FunctionEnd

The used installation folder is "C:\Users\Public\Dir2". Even if I comment the IfSilent block the installtion folder will be "C:\Users\Public\Dir1" but never the one passed via command line. What's wrong in my script?

Upvotes: 1

Views: 1742

Answers (1)

Anders
Anders

Reputation: 101569

!include LogicLib.nsh
;InstallDir ; Do not use InstallDir at all so we can detect empty $InstDir
!define DEFDIR_MACHINE "$programfiles\foo"
!define DEFDIR_PERUSER "$localappdata\bar"
Function .onInit
${If} $InstDir == "" ; /D not used
    ${If} $MultiUser.InstallMode == "AllUsers"
        StrCpy $InstDir "${DEFDIR_MACHINE}"
    ${Else}
        StrCpy $InstDir "${DEFDIR_PERUSER}"
    ${EndIf}
    ${If} ${Silent}
        StrCpy $InstDir "c:\CrazySilentOverride"
    ${EndIf}
${EndIf}
FunctionEnd

Upvotes: 2

Related Questions