在IF ELSE块中安装InstallDir

时间:2011-11-28 10:01:11

标签: nsis

我尝试从

获取以下代码
; The default installation directory
InstallDir $PROGRAMFILES\${PRODUCT_NAME}

!include x64.nsh
${If} ${RunningX64}
    ; The default installation directory
    InstallDir $PROGRAMFILES\${PRODUCT_NAME}
${Else}
    ; The default installation directory
    InstallDir $PROGRAMFILES64\${PRODUCT_NAME}
${EndIf}

我收到以下错误: -

!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

我可以在if else块中设置InstallDir的值吗?

1 个答案:

答案 0 :(得分: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

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