Search code examples
if-statementnsis

NSIS Alternative If, then, else, andif etc


My question is if there is an alternative plugin similar to LogicLib? One that does support numbers like 17.0.8.22 since my program version that's in the registry is a number like that and it seems like LogicLib does not support this for Windows 7. It does recgonize it like this:

${If} $0 = '17.0.22.0'

But this is failing/being ignored,

${If} $0 > '17.0.22.0'

Solution

  • As Anders states, the VersionCompare macro can handle complex version comparison.

    Here is a little example:

    !include "logiclib.nsh"
    !include "wordfunc.nsh"
    OutFile "version.exe"
    
    !define v1 "1.4.0"
    !define v2 "1.3"
    
    Section
    
        ${VersionCompare} "${v1}" "${v2}" $0
        ${select} $0
            ${case} 0
                messagebox MB_OK "${v1} = ${v2}"
            ${case} 1
                messagebox MB_OK "${v1} newer than ${v2}"
            ${case} 2
                messagebox MB_OK "${v1} older than ${v2}"
        ${endselect}
    
    SectionEnd