Search code examples
nsis

Is there any way that we can read the registry version number key in a generic way using NSIS?


Using NSIS when installing the newer version of the software, from specific older version no (for eg., 3.01.00) i am upgrading it to the newer version automatically by uninstalling the older version and installing newer version like as shown below:

Note: Here my older version of the software installer is using WIX and the newer installer is using NULLSOFT

 ReadRegStr $R1 HKLM "SOFTWARE\Millinnium\3.01.00" "InstallPath"
  ReadRegStr $R2 HKLM "SOFTWARE\Millinnium\3.02.00" "InstallPath"

${If} $R1 != ""

MessageBox MB_YESNO|MB_ICONQUESTION "$(UninstallPrevVer)" IDYES noUninstOld

Abort
 noUninstOld:
 ExecWait '"MsiExec.exe" /X{8ED262EE-FC73-47A9-BB86-D92223246881} /qb!'  


${ElseIf} $R2 != ""

MessageBox MB_YESNO|MB_ICONQUESTION "$(UninstallPrevVer)" IDYES noUninstOld

Abort
 noUninstOld:
 ExecWait '"MsiExec.exe" /X{8ED262EE-FC73-47A9-BB86-D92223246881} /qb!'  

${EndIf}

But if i have much older versions for eg., <3.01.00 (i.e., 3.0 or 3.0.0.1 or 2.0 or lesser) I wanted to display a generic message displayed stating to uninstall the existing version manually before installing the newer version.

Is there any way that we can read the registry version number key in a generic way?

or do i need to follow for each version like as shown below?

 ReadRegStr $R1 HKLM "SOFTWARE\Millinnium\3.0" "InstallPath"
  ReadRegStr $R2 HKLM "SOFTWARE\Millinnium\3.0.0.1" "InstallPath"
ReadRegStr $R2 HKLM "SOFTWARE\Millinnium\2.0" "InstallPath"

Solution

  • Use EnumRegKey to enumerate keys:

    Section
    StrCpy $0 0
    loop:
      EnumRegKey $1 HKLM "SOFTWARE\Millinnium" $0
      StrCmp $1 "" done
      IntOp $0 $0 + 1
      DetailPrint "Key: $1"
      Goto loop
    done:
    SectionEnd
    

    SectionEnd