Inno Setup 检测已安装的.NET Framework 版本

2016-08-23 08:18:40来源:cnblogs.com作者:DelphiFarmer人点击

翻译自:http://kynosarges.org/DotNetVersion.html

由 Jordan Russell 写的 Inno Setup 是一个伟大的安装脚本程序,但缺乏一个内置的函数来确定安装在目标机器上的.NET Framework版本。幸运的是,它很容易使用 Pascal 脚本语言来实现这样的功能。

脚本

在下面的 Inno Setup的 脚本代码块,函数 IsDotNetDetected 检查指定的.NET Framework 版本和至少指定的服务包级别是否被安装了。所有列出的版本字符串是最终的发行版本; 测试版和发布候选通常具有不同的版本号。函数 InitializeSetup 演示了如何使用 IsDotNetDetected 检查 .NET Framework 4.6 是否有服务包。

我把在公共域代码这个小一点,这样你可以将它嵌入到自己的项目,修改和重新发布它,你认为合适。

 1 [Code] 2 function IsDotNetDetected(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.1 7 //    'v2.0'          .NET Framework 2.0 8 //    'v3.0'          .NET Framework 3.0 9 //    'v3.5'          .NET Framework 3.510 //    'v4/Client'     .NET Framework 4.0 Client Profile11 //    'v4/Full'       .NET Framework 4.0 Full Installation12 //    'v4.5'          .NET Framework 4.513 //    'v4.5.1'        .NET Framework 4.5.114 //    'v4.5.2'        .NET Framework 4.5.215 //    'v4.6'          .NET Framework 4.616 //    'v4.6.1'        .NET Framework 4.6.117 //    'v4.6.2'        .NET Framework 4.6.218 //19 // service -- Specify any non-negative integer for the required service pack level:20 //    0               No service packs required21 //    1, 2, etc.      Service pack 1, 2, etc. required22 var23     key, versionKey: string;24     install, release, serviceCount, versionRelease: cardinal;25     success: boolean;26 begin27     versionKey := version;28     versionRelease := 0;29 30     // .NET 1.1 and 2.0 embed release number in version key31     if version = 'v1.1' then begin32         versionKey := 'v1.1.4322';33     end else if version = 'v2.0' then begin34         versionKey := 'v2.0.50727';35     end36 37     // .NET 4.5 and newer install as update to .NET 4.0 Full38     else if Pos('v4.', version) = 1 then begin39         versionKey := 'v4/Full';40         case version of41           'v4.5':   versionRelease := 378389;42           'v4.5.1': versionRelease := 378675; // 378758 on Windows 8 and older43           'v4.5.2': versionRelease := 379893;44           'v4.6':   versionRelease := 393295; // 393297 on Windows 8.1 and older45           'v4.6.1': versionRelease := 394254; // 394271 on Windows 8.1 and older46           'v4.6.2': versionRelease := 394802; // 394806 on Windows 8.1 and older47         end;48     end;49 50     // installation key group for all .NET versions51     key := 'SOFTWARE/Microsoft/NET Framework Setup/NDP/' + versionKey;52 53     // .NET 3.0 uses value InstallSuccess in subkey Setup54     if Pos('v3.0', version) = 1 then begin55         success := RegQueryDWordValue(HKLM, key + '/Setup', 'InstallSuccess', install);56     end else begin57         success := RegQueryDWordValue(HKLM, key, 'Install', install);58     end;59 60     // .NET 4.0 and newer use value Servicing instead of SP61     if Pos('v4', version) = 1 then begin62         success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);63     end else begin64         success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);65     end;66 67     // .NET 4.5 and newer use additional value Release68     if versionRelease > 0 then begin69         success := success and RegQueryDWordValue(HKLM, key, 'Release', release);70         success := success and (release >= versionRelease);71     end;72 73     result := success and (install = 1) and (serviceCount >= service);74 end;75 76 77 function InitializeSetup(): Boolean;78 begin79     if not IsDotNetDetected('v4.6', 0) then begin80         MsgBox('MyApp requires Microsoft .NET Framework 4.6.'#13#1381             'Please use Windows Update to install this version,'#1382             'and then re-run the MyApp setup program.', mbInformation, MB_OK);83         result := false;84     end else85         result := true;86 end;

 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台