How can I use conditional execution (If ... EndIf equivalent)?

From NSIS Wiki

The LogicLib provides macros for logical structures such as conditional execution and loops. To use the LogicLib, add the following at the top of the script:

!include LogicLib.nsh

Then, you can use ${If}, ${Else} and more.

${If} $R0 == "bla"
  MessageBox MB_OK "$$R0 is 'bla'"
${Else}
  MessageBox MB_OK "$$R0 is not 'bla'"
${EndIf}

See LogicLib.nsi for more examples.

You can also use the good old commands like StrCmp and IntCmp. Example (If ... EndIf equalivent):

StrCmp $R0 "bla" 0 nobla ;Goes to nobla when $R0 =! bla, otherwise continue
  ;...Do something when $R0 = bla...
nobla:

You can also use multiple commands. Example (If ... ElseIf ... EndIf equalivent):

StrCmp $R0 "bla" 0 nobla ;Goes to nobla when $R0 =! bla, otherwise continue
  ;...Do something when $R0 = bla...
  Goto done ;Do nothing else
nobla:
 
StrCmp $R0 "bla2" 0 done ;Goes to done when $R0 =! bla2, otherwise continue
  ;...Do something when $R0 = bla2...
done:
Personal tools
donate
ads