gpt4 book ai didi

nsis - 在 IF ELSE block 中有 InstallDir

转载 作者:行者123 更新时间:2023-12-04 14:17:44 24 4
gpt4 key购买 nike

我尝试从以下代码中获取

; 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

有什么方法可以设置 InstallDir 的值吗? , 在 if else 块内?

最佳答案

如果你需要一个动态的 $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 ...

关于nsis - 在 IF ELSE block 中有 InstallDir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8294169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com