解决方法
当Inno Setup可执行文件运行时,InitializeSetup函数被调用。为自定义脚本插入此代码应该做您想要的:
function IsDotNetDetected(version: string; service: cardinal): boolean; // Indicates whether the specified version and service pack of the .NET Framework is installed. // // version -- Specify one of these strings for the required .NET Framework version: // 'v1.1.4322' .NET Framework 1.1 // 'v2.0.50727' .NET Framework 2.0 // 'v3.0' .NET Framework 3.0 // 'v3.5' .NET Framework 3.5 // 'v4\Client' .NET Framework 4.0 Client Profile // 'v4\Full' .NET Framework 4.0 Full Installation // // service -- Specify any non-negative integer for the required service pack level: // 0 No service packs required // 1,2,etc. Service pack 1,etc. required var key: string; install,serviceCount: cardinal; success: boolean; begin key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version; // .NET 3.0 uses value InstallSuccess in subkey Setup if Pos('v3.0',version) = 1 then begin success := RegQueryDWordValue(HKLM,key + '\Setup','InstallSuccess',install); end else begin success := RegQueryDWordValue(HKLM,key,'Install',install); end; // .NET 4.0 uses value Servicing instead of SP if Pos('v4',version) = 1 then begin success := success and RegQueryDWordValue(HKLM,'Servicing',serviceCount); end else begin success := success and RegQueryDWordValue(HKLM,'SP',serviceCount); end; result := success and (install = 1) and (serviceCount >= service); end; function InitializeSetup(): Boolean; begin if not IsDotNetDetected('v4\Client',0) then begin MsgBox('MyApp requires Microsoft .NET Framework 4.0 Client Profile.'#13#13 'Please use Windows Update to install this version,'#13 'and then re-run the MyApp setup program.',mbInformation,MB_OK); result := false; end else result := true; end;
(代码摘自:http://www.kynosarges.de/DotNetVersion.html)
首先,它检查是否存在指示已安装的.NET框架版本的注册表项。如果注册表项不存在,它会提示用户下载.NET框架。如果用户说“是”,则会打开下载URL。 (您可能必须将其在脚本中指定的版本更改为版本4.0。)
我也遇到了this article on CodeProject,这可能是一个更全面和可定制的方式来做你正在寻找,虽然可能需要更多的工作要了解,将必须修改与4.0版本的工作。