Skip to content
⌘ NSIS Forum Archive

ReadRegStr seems to be pulling old values

3 posts

jpps#

ReadRegStr seems to be pulling old values

I have a function that is checking for the minimum versions of MSSQLExpress installed on a server. When i test the installer with a version lower than the required versions the code works and errors out with my expected message. When i upgrade MSSQLExpress to the required version or above it will still act like it's reading the original version number and continue to error out. I have checked the registry key that it's looking for and it's updating with the correct value but my installer is still coming back with the older version number. This behavior persists through reboots as well.


Here is the section of code that has the logic. Everything else is just Messages for the user.


ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion" "CurrentVersion"
IfErrors SQLServerNotFound SQLServerFound1

SQLServerFound1:
StrCpy $1 $0 2
StrCmp $1 "10" SQLServer2008Found SQLServerFound2
SQLServerFound2:
StrCpy $1 $0 2
StrCmp $1 "11" SQLServer2012Found SQLServerVersionError

SQLServer2008Found:

Push $0
Push "."
Call StrTok ;For an example string of "10.50.6000", "10" and "50.6000" now on stack
Pop $2
Push "."
Call StrTok ;"50" and "6000" now on stack
Pop $2
Pop $3

${VersionCompare} $3 6000 $R0
${If} $R0 == "0"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "1"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "2"
!ifndef SQLVersion
!define SQLVersion "SQLServer 2008 R2 version of SP3 10.50.6000"
!endif
Goto SQLServerVersionError
${EndIf}
Goto ExitCheckMinSQLVersionNonAbort

SQLServer2012Found:

Push $0
Push "."
Call StrTok ;For an example string of "11.0.6020", "11" and "0.6020" now on stack
Pop $2
Push "."
Call StrTok ;"0" and "6020" now on stack
Pop $2
Pop $3

${VersionCompare} $3 2100 $R0
${If} $R0 == "0"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "1"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "2"
!ifndef SQLVersion
!define SQLVersion "SQLServer 2012 Version of SP3 11.0.6020"
!endif
Goto SQLServerVersionError
${EndIf}
Goto ExitCheckMinSQLVersionNonAbort
jpps#
Here's a little clearer example of what's happening. Lets say I have MSSQLExpress version 10.50.4000 installed. So I run this command and it will come back with that version string.


ReadRegStr $1 HKLM "SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion" "CurrentVersion"
But, then I install SP3 which brings the version number in the registry up to 10.50.6000. The same exact command that worked before looking at the same registry key that has updated if you look at it in regedit, still shows the old version number.

I don't really understand why it's still showing the old version number when you can look in regedit and see that the version has updated?
JasonFriday13#
Perhaps it's a 32bit/64bit issue. Try switching the registry view to 64bit, read from the registry, and set it back to 32bit. Reference:http://nsis.sourceforge.net/Docs/Cha...tml#setregview.