Archive: My MySQL registry checker


My MySQL registry checker
As I didn't found a script on the nsis page to detect MySQL in the registry, I just wrote mine and decided to share it.
I'm new to NSIS coding so feel free to make a better code ;)

To use it :
Var $path_result
Var $version_result
!insertmacro CheckMySqlReg $path_result $version_result
DetailPrint "MySQL : located in $path_result with version $version_result"


!macro CheckMySqlReg _RESULT _RESULT2
Push $0
Push $1
Push $2
Push $R0
StrCpy $0 0
StrCpy ${_RESULT} ""
StrCpy ${_RESULT2} ""
loopSqlReg:
ClearErrors
EnumRegKey $1 HKLM "Software\MYSQL AB" $0
StrCmp $1 "" doneSqlReg
IntOp $0 $0 + 1
StrCpy $2 $1 12
StrCmp $2 "MySQL Server" foundSqlReg 0
Goto loopSqlReg
foundSqlReg:
ReadRegStr $R0 HKLM "Software\MYSQL AB\$1" "Location"
IfFileExists "$R0\bin\mysql.exe" 0 doneSqlReg
StrCpy ${_RESULT} "$R0"
ReadRegStr $R0 HKLM "Software\MYSQL AB\$1" "Version"
StrCpy ${_RESULT2} "$R0"
doneSqlReg:
Pop $0
Pop $1
Pop $2
Pop $R0
!macroend


It'd be better whenever you want to share NSIS code to post it at wiki. This makes it easier for others to find it.
A quick look on the code; if you really want to preserve the values of $0, $1, $2, $R0, you should turn upside down when you Pop, see here , also probably you do not need StrCpy ${_RESULT} "" and StrCpy ${_RESULT2} "", while declared variables $path_result and $version_result are already empty :)


thank you for the tip :)


I had a similar requirement where i needed to detect MSDE /MSSQL and run the uninstaller path.
I used registry.nsh plugin to locate the path ,
then using that path, locate and run a substring :
(extracted code)


!include "registry.nsh"

Function UninstallMSDE

### Get dynamic registry path by searching for MSDE (full name) and store path as $1
### Using $1 search for uninstall path - store as $R3
### Execute $R3 (msde uninstall path)

${registry::Open} "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" "/K=0 /V=0 /S=1 /B=1 /NS='Microsoft SQL Server Desktop Engine'" $0
StrCmp $0 0 0 loop
MessageBox MB_OK "Error getting MSDE registry entry use Add/Remove programs" IDOK close

loop:
${registry::Find} "$0" $1 $2 $3 $4

${registry::Open} "HKLM\$1" "/K=0 /V=1 /S=0 /B=1 /NS='UninstallString'" $R6
StrCmp $R6 0 0 loop2
MessageBox MB_OK "Error getting MSDE Uninstall registry entry use Add/Remove programs" IDOK close

loop2:
${registry::Find} "$R6" $R1 $R2 $R3 $R4

ExecWait $R3
close:
${registry::Close} "$0"
${registry::Unload}

FunctionEnd


It can probably be cleaned up a little - i really only modified the example scripts included in the plugin and cut it.

Unless RW and co see any major problems with the code i shall add it to WiKi later this week.

My opinion is this; contribution should be our duty, this is the way NSIS grows up and spreads all over.