We are working on converting the wiki to a static website controlled by markdown files in https://github.com/nsis-community. You can already see there how plug-ins will be posted. The end-user interface will still be a website but with a fresh coat of paint. Come meet us at Discord to talk about it.

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

From NSIS Wiki
Jump to navigationJump to search

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: