Translated from: http://kynosarges.org/DotNetVersion.html
Inno Setup, written by Jordan Russell , is a great setup script, but lacks a built-in function to determine which version of the. NET Framework is installed on the target machine. Fortunately, it is easy to use the Pascal scripting language to implement such a feature.
Script
In the following Inno Setup script code block, the function IsDotNetDetected
checks whether the specified. NET Framework version and at least the specified service pack level are installed. All the listed version strings are the final release version; Beta and release candidates typically have different version numbers. InitializeSetup
The function demonstrates how to use to IsDotNetDetected
check whether the. NET Framework 4.6 has a service pack.
I put this small point in the public domain code so that you can embed it into your own project, modify and republish it as you see fit.
1 [Code]2 functionIsdotnetdetected (version:string; service:cardinal): boolean;3 //indicates whether the specified version and service pack of the. NET Framework is installed.4 //5 //version--Specify one of these strings for the required. NET Framework version:6 //' v1.1 '. NET Framework 1.17 //' v2.0 '. NET Framework 2.08 //' v3.0 '. NET Framework 3.09 //' v3.5 '. NET Framework 3.5Ten //' v4\client '. NET Framework 4.0 Client profile One //' V4\full '. NET Framework 4.0 Full installation A //' v4.5 '. NET Framework 4.5 - //' v4.5.1 '. NET Framework 4.5.1 - //' v4.5.2 '. NET Framework 4.5.2 the //' v4.6 '. NET Framework 4.6 - //' v4.6.1 '. NET Framework 4.6.1 - //' v4.6.2 '. NET Framework 4.6.2 - // + //Service--Specify any non-negative integer for the required service pack level: - //0 No Service packs required + //1, 2, etc. Service Pack 1, 2, etc. Required A var atKey, Versionkey:string; - install, release, Servicecount, versionrelease:cardinal; - Success:boolean; - begin -Versionkey: =version; -Versionrelease: =0; in - //. NET 1.1 and 2.0 embed release number in version key to ifVersion ='v1.1' Then begin +Versionkey: ='v1.1.4322'; - End Else ifVersion ='v2.0' Then begin theVersionkey: ='v2.0.50727'; * End $ Panax Notoginseng //. NET 4.5 and newer install as update to. NET 4.0 - Else ifPos ('v4.', version) =1 Then begin theVersionkey: ='V4\full'; + CaseVersion of A 'v4.5': versionrelease: =378389; the 'v4.5.1': versionrelease: =378675;//378758 on Windows 8 and older + 'v4.5.2': versionrelease: =379893; - 'v4.6': versionrelease: =393295;//393297 on Windows 8.1 and older $ 'v4.6.1': versionrelease: =394254;//394271 on Windows 8.1 and older $ 'v4.6.2': versionrelease: =394802;//394806 on Windows 8.1 and older - End; - End; the - //installation key group for all. NET versionsWuyiKey: ='software\microsoft\net Framework setup\ndp\'+Versionkey; the - //. NET 3.0 uses value Installsuccess in subkey Setup Wu ifPos ('v3.0', version) =1 Then begin -Success: = Regquerydwordvalue (HKLM, key +'\setup','installsuccess', install); About End Else begin $Success: = Regquerydwordvalue (HKLM, Key,'Install', install); - End; - - //. NET 4.0 and newer use value servicing instead of SP A ifPos ('V4', version) =1 Then begin +Success: = Success andRegquerydwordvalue (HKLM, Key,'Servicing', servicecount); the End Else begin -Success: = Success andRegquerydwordvalue (HKLM, Key,'SP', servicecount); $ End; the the //. NET 4.5 and newer use additional value Release the ifVersionrelease >0 Then begin theSuccess: = Success andRegquerydwordvalue (HKLM, Key,'Release', release); -Success: = Success and(Release >=versionrelease); in End; the theResult: = Success and(Install =1) and(Servicecount >=service); About End; the the the functionInitializesetup (): Boolean; + begin - if notIsdotnetdetected ('v4.6',0) Then begin theMsgBox ('MyApp requires the Microsoft. NET Framework 4.6.'# -# -Bayi 'Use the Windows Update to install the This version,'# - the 'And then re-run the MYAPP Setup program.', Mbinformation, MB_OK); theResult: =false; - End Else -Result: =true; the End;
Inno Setup detects the installed. NET Framework version