在IF ELSE块中安装InstallDir

Che*_*eng 6 nsis

我尝试从以下代码

; The default installation directory
InstallDir $PROGRAMFILES\${PRODUCT_NAME}
Run Code Online (Sandbox Code Playgroud)

!include x64.nsh
${If} ${RunningX64}
    ; The default installation directory
    InstallDir $PROGRAMFILES\${PRODUCT_NAME}
${Else}
    ; The default installation directory
    InstallDir $PROGRAMFILES64\${PRODUCT_NAME}
${EndIf}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: -

!insertmacro: _If
Error: Can't add entry, no section or function is open!
Error in macro _RunningX64 on macroline 2
Error in macro _If on macroline 9
Error in script "C:\Users\yccheok\Desktop\mysoftware.nsi" on line 17 -- aborting creation process
Run Code Online (Sandbox Code Playgroud)

有没有办法我可以InstallDir在if else块中设置值?

And*_*ers 9

如果你需要一个动态$ InstDir,你根本不应该使用InstallDir,而是在.onInit中设置$ InstDir:

Installdir ""
!include LogicLib.nsh
!include x64.nsh

Function .onInit
${If} $InstDir == "" ; /D= was not used on the command line
    ${If} ${RunningX64}
        StrCpy $InstDir "c:\foo"
    ${Else}
        StrCpy $InstDir "c:\bar"
    ${EndIf}
${EndIf}
FunctionEnd
Run Code Online (Sandbox Code Playgroud)

您当前的if else块没有任何意义,因为您正在选择x64上的32位程序文件和x86上的64位程序文件!在x86上使用$ PROGRAMFILES64是可以的,所以如果你总是想要"真正的"程序文件,你可以在所有平台上使用$ PROGRAMFILES64 ......