Skip to content
⌘ NSIS Forum Archive

How to implement If Else Endif condition (e.g if ${OUT3} = 1...read the msg)

3 posts

Swapan Das#

How to implement If Else Endif condition (e.g if ${OUT3} = 1...read the msg)

I have an issue where if else condition is to be used. I want to check my bundled exe(s)
of my installer with the client's exe and as per the condition I have to upgrade the
user's exe.

I did the following things:

Var Out1
Var Out2
Var Out3
Var BundledExe1 ; MyExe1.exe
Var BundledExe2 ; MyExe2.exe
Var BundledExe3 ; MyExe3.exe

Section ..
;I hard-coded my bundled exe's version in variable
;BundledExe1:
StrCpy $BundledExe1 "5.166.0.29"
${GetFileVersion} '$INSTDIR\MyExe1.exe' $OUT2
${VersionCompare} $BundledExe1 $OUT2 $OUT3

The variable OUT3 is storing the result of versioncompare,which is correct.
Now I want to do something like this with if else branch-out:
if ${OUT3} = 1
MessageBox MB_OK "Older version found - going for upgradation"
.... do the necessary jobs
elseif ${OUT3} = 0
MessageBox MB_OK "SAME VERSION - NO UPGRADE"
.... do the necessary jobs
elseif ${OUT3} = 2
MessageBox MB_OK "UR Version is higher- NO UPGRADE"
.... do the necessary jobs
endif

;;;; i've tried to use the following code but it is giving error:
${If} ${OUT3} ='1'
${Else}
${EndIf}

SectionEnd
Filus#
${If} ${OUT3} ='1'
${Else}
${EndIf}
It is because, instead of ${OUTx}, you should have $OUTx for variables. And probably, you should use == for comparision (but I'm not sure, see LogicLib docs).
Swapan Das#
Thanks Filus for prompt response.

I've done this and its working fine:
${If} $OUT3 = 1
${ElseIf} $OUT3 = 2
${ElseIf} $OUT3 = 0
${EndIf}

With regards,
Swapan Das