Detecting the installed version of PostgreSQL
Does anyone have an example of a NSIS script that checks for the current install version of PostgreSQL?
Thanks, David Robison
Archive: Detecting the installed version of PostgreSQL
Detecting the installed version of PostgreSQL
Does anyone have an example of a NSIS script that checks for the current install version of PostgreSQL?
Thanks, David Robison
Take a look under HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations in the registry. Each installation has a value called Version. You can read this information using ReadRegStr.
Basil
Thanks, in case anyone else is interested, here is the function I developed to check for the version:
; Returns: 0 - PostgreSQL not found. -1 - PostgreSQL found but too old. Otherwise - PostgreSQL version
; DetectPostgreSQL. Version requested is on the stack.
; Returns (on stack) "0" on failure (java too old or not installed), otherwise path to java interpreter
; Stack value will be overwritten!
Function DetectPostgreSQL
Exch $0 ; Get version requested
; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0
Push $1 ; $1 = PostgreSQL version string (ie 8.2)
Push $2 ; $2 = registry key
; scan through all installs to get the highest version
StrCpy $0 0
DetectPostgreSQLLoop:
EnumRegKey $2 HKLM "Software\PostgreSQL\Installations" $0
StrCmp $2 "" DetectPostgreSQLDone
ReadRegStr $1 HKLM "Software\PostgreSQL\Installations\$2" "Version"
ReadRegStr $3 HKLM "Software\PostgreSQL\Installations\$2" "Base Directory"
IntOp $0 $0 + 1
goto DetectPostgreSQLLoop
DetectPostgreSQLDone:
StrCmp $1 "" NoFound
IntCmp $1 $0 FoundNew FoundOld FoundNew
NoFound:
Push "0"
Goto DetectPostgreSQLEnd
FoundOld:
Push "-1"
Goto DetectPostgreSQLEnd
FoundNew:
Push "$3"
Goto DetectPostgreSQLEnd
DetectPostgreSQLEnd:
; Top of stack is return value, then r4,r3,r2,r1
Exch ; => r2,rv,r1,r0
Pop $2 ; => rv,r1,r0
Exch ; => r1,rv,r0
Pop $1 ; => rv,r0
Exch ; => r0,rv
Pop $0 ; => rv
FunctionEnd
that was quick :)
thanks for sharing!
two things you might want to additionally check for depending on what your installer does:
1) see if postmaster.exe exists under the base directory you read from the registry.
2) check and see if postmaster.exe is actually running (you can use the plugin at http://nsis.sourceforge.net/Find_Process_By_Name )
Basil