Search code examples
registrynsis

Why is my NSIS code not picking up a Registry key?


I have been trawling lots of related Qs such as this one, but been struggling to get my first NSIS installer up and running.

The installer is specific for 64bit machines (other code captures this and aborts if 32bit).

I just need to return a value of 0 (no install found, 1 (v9 found) or 2 (v10 found).

At the moment, if I run this NSIS on a machine in all three scenarios, it always returns a 0.

Can someone point me to what I have done wrong in the logic of the code?
It is also likely that I have not done this in the most elegant of ways, so would really appreciate a snippet of a better approach, ideally with some reasoning.

Var AGSv

Section "Check AGS" SEC01  
call CheckAGS
 Pop $R0
 messagebox MB_OK $AGSv 
SectionEnd

;Check to see if AGS is installed, and which version.
Function CheckAGS
        ;This is the key for v10
        ReadRegStr $1 HKLM "SOFTWARE\Wow6432Node\ESRI\Server10.0\CoreRuntime" "RealVersion"
        ${If} $1 == ""
          GoTo Try931
        ${Else}
          StrCpy $AGSv 2  
        ${EndIf}
        ;This is the key for v9
        Try931:
        ReadRegStr $2 HKLM "SOFTWARE\Wow6432Node\ESRI\ArcServer\Microsoft .NET Framework Edition" "RealVersion"
        ${If} $2 == ""
          GoTo NoAGS
        ${Else}
          StrCpy $AGSv 1 
        ${EndIf}    
    NoAGS:
    StrCpy $AGSv 0
    Messagebox MB_OK "No AGS installation detected."
FunctionEnd

Solution

  • The problem is your goto logic in the function, the StrCpy $AGSv 0 line always gets executed (And you never push anything so the pop after call CheckAGS gets a "random" value)

    Function CheckAGS
    ReadRegStr $1 HKLM "SOFTWARE\Wow6432Node\ESRI\Server10.0\CoreRuntime" "RealVersion"
    ${If} $1 != ""
        StrCpy $AGSv 2
        return
    {EndIf}
    ReadRegStr $1 HKLM "SOFTWARE\Wow6432Node\ESRI\ArcServer\Microsoft .NET Framework Edition" "RealVersion"
    ${If} $1 != ""
        StrCpy $AGSv 1
        return
    {EndIf}
    StrCpy $AGSv 0 ;not found
    Messagebox MB_ICONSTOP "No AGS installation detected."
    FunctionEnd
    

    You should not use Wow6432Node directly, to read from the 64 bit registry use SetRegView...