NSIS——检测SQL Server安装版本

来自:http://nsis.sourceforge.net/How_to_tell_what_version_of_SQLServer_is_installed

1、代码如下:
 
Function StrTok
Exch $R1
Exch 1
Exch $R0
Push $R2
Push $R3
Push $R4
Push $R5
 
;R0 fullstring
;R1 tokens
;R2 len of fullstring
;R3 len of tokens
;R4 char from string
;R5 testchar
 
StrLen $R2 $R0
IntOp $R2 $R2 + 1
 
loop1:
IntOp $R2 $R2 - 1
IntCmp $R2 0 exit
 
StrCpy $R4 $R0 1 -$R2
 
StrLen $R3 $R1
IntOp $R3 $R3 + 1
 
loop2:
IntOp $R3 $R3 - 1
IntCmp $R3 0 loop1
 
StrCpy $R5 $R1 1 -$R3
 
StrCmp $R4 $R5 Found
Goto loop2
Goto loop1
 
exit:
;Not found!!!
StrCpy $R1 ""
StrCpy $R0 ""
Goto Cleanup
 
Found:
StrLen $R3 $R0
IntOp $R3 $R3 - $R2
StrCpy $R1 $R0 $R3
 
IntOp $R2 $R2 - 1
IntOp $R3 $R3 + 1
StrCpy $R0 $R0 $R2 $R3
 
Cleanup:
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Exch $R0
Exch 1
Exch $R1
 
FunctionEnd
;--------------------------------
; CheckMinSQLVersion
;
; Written by Matthew Kershaw (matthew.kershaw@us.didata.com)
;
; For this function the min SQL version must be SQL2kSP2 ...
; typically the SQLServer version is located in
; HKLM\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion\CurrentVersion
; but for SPs, the new version is located in
; HKLM\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion\CSDVersion.
; For SP2, the value is 8.00.534. If the CSDVersion key does not exist,
; no SP has been installed.
Function CheckMinSQLVersion
 
ClearErrors
 
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion" "CurrentVersion"
IfErrors SQLServerNotFound SQLServerFound
 
SQLServerFound:
ReadRegStr $4 HKLM "SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion" "CSDVersion"
IfErrors SPNotFound SPFound
 
SPFound:
 
;Check the first digit of the version; must be 8
StrCpy $0 $4
StrCpy $1 $0 1
StrCmp $1 "8" SQLServer2000Found SQLServerVersionError
Goto ExitCheckMinSQLVersion
 
SQLServer2000Found:
 
Push $0
Push "."
Call StrTok;For an example string of "8.00.194", "8" and "00.194" now on stack
Pop $2
Push "."
Call StrTok;"00" and "194" now on stack
Pop $2
Pop $3
 
IntCmp $3 534 0 SQLServerVersionError 0
Push 1
Goto ExitCheckMinSQLVersion
 
SQLServerVersionError:
MessageBox MB_OK|MB_ICONEXCLAMATION "此产品需要SQLServer的最低版本为 v8.00.534 (SQLServer 2000, SP2);检测到当前版本为$0。安装程序将中止。"
Push 0
Goto ExitCheckMinSQLVersion
 
SQLServerNotFound:
MessageBox MB_OK|MB_ICONEXCLAMATION "安装程序未能检测到Microsoft SQLServer,这是必须安装的。安装程序将中止。"
Push 0
Goto ExitCheckMinSQLVersion
 
SPNotFound:
MessageBox MB_OK|MB_ICONEXCLAMATION "MicrosfotSQLServer v $0 已安装。SQLServer 2000 SP2 (or later)必须安装。安装程序将中止。"
Push 0
Goto ExitCheckMinSQLVersion
 
ExitCheckMinSQLVersion:
 
FunctionEnd
 
2、调用
Call CheckMinSQLVersion
Pop $0
IntCmp $0 1 +2
Abort
原文地址:https://www.cnblogs.com/juin/p/2564533.html