Blame | Last modification | View Log | RSS feed
;------------------------------------------------------------------------------; Code originally from http://nsis.sourceforge.net/How_to_ensure_a_required_version_of_.NET_Framework_is_installed;; This macro checks that a specified dot net version is present in the target; machine.;; usage:; !insertmacro DotNetSearch 4 0 30319 "ABORT" "";; Parameters:; 1 DOTNETVMAJOR Compulsory, minimum major version required; 2 DOTNETVMINOR Compulsory, minimum minor version required; 3 DOTNETVMINORMINOR Option minimum build version required. Set to "" if not important; 4 DOTNETLASTFUNCTION What to do if no dot net found; One of the following :; INSTALL_ABORT : Give user option of installing it, or aborting; INSTALL_NOABORT : Give user option of installing it, or returning; to caller and let them decide on action needed; WARNING : Just issue a warning and return to caller and let; them decide on action needed; ABORT : Abort the installer; IGNORE : Just return to caller and let them decide on; action needed; 5 DOTNETINSTALLEREXE Path to dotnet exe to install the dotnet framework;------------------------------------------------------------------------------Var /GLOBAL DNS_RETVALVar /GLOBAL DNS_SUBKEYVar /GLOBAL DNS_REGKEY2Var /GLOBAL DNS_REGKEYVar /GLOBAL DNS_TMPSTRVar /GLOBAL DNS_ENUMINDEXVar /GLOBAL DNA_INSTALLROOTVar /GLOBAL DOTNETPATH!macro DotNetSearch DOTNETVMAJOR DOTNETVMINOR DOTNETVMINORMINOR DOTNETLASTFUNCTION DOTNETINSTALLEREXEPush $DNS_RETVALPush $DNS_SUBKEYPush $DNS_REGKEY2Push $DNS_REGKEYPush $DNS_TMPSTRPush $DNS_ENUMINDEXPush $DNA_INSTALLROOTStrCpy $DNS_RETVAL "0"StrCpy $DNS_SUBKEY "SOFTWARE\Microsoft\.NETFramework"StrCpy $DNS_ENUMINDEX 0; Here is where we start to iterate over the registry area that lists evidence of the installed dotnet frameworksDotNetStartEnum:; Look in HKLM\SOFTWARE\Microsoft\.NETFramework\policy for v?.?EnumRegKey $DNS_REGKEY HKLM "$DNS_SUBKEY\policy" $DNS_ENUMINDEXStrCmp $DNS_REGKEY "" noDotNet dotNetFounddotNetFound:; Does entry begin with "v"?StrCpy $DNS_TMPSTR $DNS_REGKEY 1 0StrCmp $DNS_TMPSTR "v" +1 goNextDotNet; Examine major version of in the "v?.?" stringStrCpy $DNS_TMPSTR $DNS_REGKEY 1 1IntCmp $DNS_TMPSTR ${DOTNETVMAJOR} +1 goNextDotNet yesDotNetReg; Examine minor version of in the "v?.?" stringStrCpy $DNS_TMPSTR $DNS_REGKEY 1 3IntCmp $DNS_TMPSTR ${DOTNETVMINOR} +1 goNextDotNet yesDotNetReg; Has caller specified a dotnet BUILD version number ?StrCmp ${DOTNETVMINORMINOR} "" yesDotNetReg +1; Look in HKLM\SOFTWARE\Microsoft\.NETFramework\policy\v?.? for the build version key and; compare it to caller specified value. It is acceptable if it is equal to or greater than; the caller specified valueEnumRegValue $DNS_TMPSTR HKLM "$DNS_SUBKEY\policy\$DNS_REGKEY" 0StrCmp $DNS_TMPSTR "" goNextDotNetIntCmpU $DNS_TMPSTR ${DOTNETVMINORMINOR} yesDotNetReg goNextDotNet yesDotNetReggoNextDotNet:; Increment index into the enumerated list of keys and advance to next iterationIntOp $DNS_ENUMINDEX $DNS_ENUMINDEX + 1Goto DotNetStartEnumyesDotNetReg:; Looks like we have a dotnet version required.; Look in HKLM\SOFTWARE\Microsoft\.NETFramework\policy\v?.? for the build version key and use it; to form a path we can check for the presence of actual files in a dotnet framework installationEnumRegValue $DNS_REGKEY2 HKLM "$DNS_SUBKEY\policy\$DNS_REGKEY" 0StrCmp $DNS_REGKEY2 "" noDotNet; Look in HKLM\SOFTWARE\Microsoft\.NETFramework\ for the installation root folder pathReadRegStr $DNA_INSTALLROOT HKLM $DNS_SUBKEY "InstallRoot"StrCmp $DNA_INSTALLROOT "" noDotNet; Check for existence of the mscorlib.dll in the file system to prove the dot net framework has been installed; DNA_INSTALLROOT contains something like "c:\WINDOWS\Microsoft.NET\Framework\"; DNS_REGKEY contains something like "v4.0"; DNS_REGKEY2 contains something like "30319"StrCpy $DOTNETPATH "$DNA_INSTALLROOT$DNS_REGKEY.$DNS_REGKEY2"StrCpy $DNS_TMPSTR "$DOTNETPATH\mscorlib.dll"IfFileExists $DNS_TMPSTR +1 noDotNet; Check for existence of the installutil.exe in the file system to prove the dot net framework has been installedStrCpy $DNS_TMPSTR "$DOTNETPATH\installutil.exe"IfFileExists $DNS_TMPSTR yesDotNet noDotNetnoDotNet:StrCmp ${DOTNETLASTFUNCTION} "INSTALL_ABORT" +1 nDN2MessageBox MB_YESNO|MB_ICONQUESTION \"You must have Microsoft .NET Framework version ${DOTNETVMAJOR}.${DOTNETVMINOR}.${DOTNETVMINORMINOR}$\nor higher installed. Install now?" \IDYES +2 IDNO +1AbortExecWait '${DOTNETINSTALLEREXE}'Goto DotNetStartEnumnDN2:StrCmp ${DOTNETLASTFUNCTION} "INSTALL_NOABORT" +1 nDN3MessageBox MB_YESNO|MB_ICONQUESTION \"Microsoft .NET Framework version ${DOTNETVMAJOR}.${DOTNETVMINOR}.${DOTNETVMINORMINOR} is not installed.$\nDo so now?" \IDYES +1 IDNO +3ExecWait '${DOTNETINSTALLEREXE}'Goto DotNetStartEnumStrCpy $DNS_RETVAL 0Goto DotNetFinishnDN3:StrCmp ${DOTNETLASTFUNCTION} "WARNING" +1 nDN4MessageBox MB_OK|MB_ICONEXCLAMATION \"Warning:$\n$\n$\t$\tMicrosoft .NET Framework version$\n$\t$\t${DOTNETVMAJOR}.${DOTNETVMINOR}.${DOTNETVMINORMINOR} is not installed!" \IDOK 0StrCpy $DNS_RETVAL 0Goto DotNetFinishnDN4:StrCmp ${DOTNETLASTFUNCTION} "ABORT" +1 nDN5MessageBox MB_OK|MB_ICONEXCLAMATION \"Error:$\n$\n$\t$\tMicrosoft .NET Framework version$\n$\t$\t${DOTNETVMAJOR}.${DOTNETVMINOR}.${DOTNETVMINORMINOR} is not installed, aborting!" \IDOK 0AbortnDN5:StrCmp ${DOTNETLASTFUNCTION} "IGNORE" +1 nDN6StrCpy $DNS_RETVAL 0Goto DotNetFinishnDN6:MessageBox MB_OK \"$(^Name) Setup internal error.$\nMacro 'DotNetSearch', parameter '4'(${DOTNETLASTFUNCTION})invalid.$\nValue must be INSTALL_ABORT|INSTALL_NOABORT|WARNING|ABORT|IGNORE$\nSorry for the inconvenience.$\n$\tAborting..." \IDOK 0AbortyesDotNet:StrCpy $DNS_RETVAL 1DotNetFinish:Pop $DNA_INSTALLROOTPop $DNS_ENUMINDEXPop $DNS_TMPSTRPop $DNS_REGKEYPop $DNS_REGKEY2Pop $DNS_SUBKEYExch $DNS_RETVAL!macroend