來自:http://nsis.sourceforge.net/How_to_tell_what_version_of_SQLServer_is_installed
1、代碼如下: Function StrTokExch $R1Exch 1Exch $R0Push $R2Push $R3Push $R4Push $R5 ;R0 fullstring;R1 tokens;R2 len of fullstring;R3 len of tokens;R4 char from string;R5 testchar StrLen $R2 $R0IntOp $R2 $R2 + 1 loop1:IntOp $R2 $R2 - 1IntCmp $R2 0 exit StrCpy $R4 $R0 1 -$R2 StrLen $R3 $R1IntOp $R3 $R3 + 1 loop2:IntOp $R3 $R3 - 1IntCmp $R3 0 loop1 StrCpy $R5 $R1 1 -$R3 StrCmp $R4 $R5 FoundGoto loop2Goto loop1 exit:;Not found!!!StrCpy $R1 ""StrCpy $R0 ""Goto Cleanup Found:StrLen $R3 $R0IntOp $R3 $R3 - $R2StrCpy $R1 $R0 $R3 IntOp $R2 $R2 - 1IntOp $R3 $R3 + 1StrCpy $R0 $R0 $R2 $R3 Cleanup:Pop $R5Pop $R4Pop $R3Pop $R2Exch $R0Exch 1Exch $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 8StrCpy $0 $4StrCpy $1 $0 1StrCmp $1 "8" SQLServer2000Found SQLServerVersionErrorGoto ExitCheckMinSQLVersion SQLServer2000Found: Push $0Push "."Call StrTok;For an example string of "8.00.194", "8" and "00.194" now on stackPop $2Push "."Call StrTok;"00" and "194" now on stackPop $2Pop $3 IntCmp $3 534 0 SQLServerVersionError 0Push 1Goto ExitCheckMinSQLVersion SQLServerVersionError:MessageBox MB_OK|MB_ICONEXCLAMATION "此產品需要SQLServer的最低版本為 v8.00.534 (SQLServer 2000, SP2);檢測到目前的版本為$0。安裝程式將中止。"Push 0Goto ExitCheckMinSQLVersion SQLServerNotFound:MessageBox MB_OK|MB_ICONEXCLAMATION "安裝程式未能檢測到Microsoft SQLServer,這是必須安裝的。安裝程式將中止。"Push 0Goto ExitCheckMinSQLVersion SPNotFound:MessageBox MB_OK|MB_ICONEXCLAMATION "MicrosfotSQLServer v $0 已安裝。SQLServer 2000 SP2 (or later)必須安裝。安裝程式將中止。"Push 0Goto ExitCheckMinSQLVersion ExitCheckMinSQLVersion: FunctionEnd 2、調用Call CheckMinSQLVersionPop $0IntCmp $0 1 +2Abort