Search code examples
nsis

Checking for Registry in NSIS


I'm using NSIS to make an executable for a project I'm doing in Visual C++ 2012 Express. Because I'm a beginner, I started with the Setup Wizard in HM NIS Edit.

I'm trying to bundle the Visual C++ 2012 Redistributable with my program, but every time the installer is re-ran, the Redistributable pops up with a "Repair" & "Remove" option, and that looks annoying.

So I decided to write a little bit of NSIS script, and this is the start of the script so far:

Var STR
Section CheckForReg

ClearErrors
ReadRegDWORD $0 HKLM "SOFTWARE\Classes\Installer\Dependencies\{8e70e4e1-06d7-470b-9f74-a51bef21088e}" "Version"

ifErrors 0 Blank
StrCpy $STR "$INSTDIR\vcredist_x86.exe"
GoTo End

Blank:
    StrCpy $STR ""
End:

SectionEnd

This piece is called at the very start of the script, and the global variable STR is applied to:

!define MUI_FINISHPAGE_RUN $STR

Shortly after.

Obviously this is a really silly way to do it, but I don't need too much out of it.

The issue is that the CheckForReg always thinks the registry doesn't exist, and doesn't move to the label Blank. As a note, I'm manually checking the registry every time, and the registry entry looks like:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{8e70e4e1-06d7-470b-9f74-a51bef21088e}]
"Version"="11.0.51106.1"
"DisplayName"="Microsoft Visual C++ 2012 Redistributable (x86) - 11.0.51106"

So the question is: Where am I going wrong with this? It looks very simple, but obviously I have something backwards.

-- Removed Code Dump


Solution

  • You can only read DWORDs with ReadRegDWORD!

    !include LogicLib.nsh ; So we don't have to use all these labels
    StrCpy $STR ""
    ReadRegStr $0 HKLM "SOFTWARE\Classes\Installer\Dependencies\{8e70e4e1-06d7-470b-9f74-a51bef21088e}" "Version"
    ${If} $0 == ""
      StrCpy $STR "$INSTDIR\vcredist_x86.exe"
    ${EndIf}