功能 w 巨集

功能 dotNETCheck

或者你可以使用我在下面寫的功能。這個使用 LogicLib.nsh 。它應該是開箱即用的,而不必知道登錄檔中的 Release 鍵的 .NET 版本值。正如現在所寫,它只檢查 4.5-4.7 之間的版本。

##
# This one requires the use of LogicLib.nsh
# Copy and paste this code somewhere like .OnInit
Function dotNETCheck
    !define CheckDOTNET "!insertmacro _CheckDOTNET"
    !macro _CheckDOTNET _RESULT _VALUE
        Push `${_VALUE}`
        Call dotNETCheck
        Pop ${_RESULT}
    !macroend
    Exch $1
    Push $0
    Push $1
    
    ${If} $1 == "4.7"
        StrCpy $R1 460798
    ${ElseIf} $1 == "4.6.2"
        StrCpy $R1 394802
    ${ElseIf} $1 == "4.6.1"
        StrCpy $R1 394254
    ${ElseIf} $1 == "4.6"
        StrCpy $R1 393295
    ${ElseIf} $1 == "4.5.2"
        StrCpy $R1 379893
    ${ElseIf} $1 == "4.5.1"
        StrCpy $R1 378675
    ${ElseIf} $1 == "4.5"
        StrCpy $R1 378389
    ${Else}
        Goto dotNET_FALSE
    ${EndIf}
    
    ReadRegDWORD $R0 HKLM `SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full` `Release`
    IfErrors dotNET_FALSE
    
    IntCmp $R0 $R1 dotNET_TRUE dotNET_FALSE
    
    dotNET_TRUE:
    StrCpy $0 true
    Goto dotNET_END
    
    dotNET_FALSE:
    StrCpy $0 false
    SetErrors
    
    dotNET_END:    
    Pop $1
    Exch $0
FunctionEnd

##
# USAGE
# ${CheckDOTNET} $0 "Version Number"
##
# $0 Will hold the version number of the installed .NET
# If $0 is empty ($0 == "") then the error flag is set.
${CheckDOTNET} $0 "4.5"
IfErrors 0 +4
MessageBox MB_ICONSTOP|MB_TOPMOST `You must have v4.5 or greater of the .NET Framework installed. Launcher aborting!`
Call Unload
Quit
StrCmpS $0 true 0 -3