Check .NET Version with Inno Setup

原文  http://www.kynosarges.de/DotNetVersion.html

Inno Setup by Jordan Russell is a great installation scripting program, but lacks a built-in function to determine the .NET Framework version installed on the target machine. Fortunately, it’s easy to write such a function using Inno Setup’s Pascal scripting language.

Microsoft maintains a set of registry keys that indicate the installed .NET Framework versions and service packs. C# MVP Scott Dorman has posted a list comprising versions 1.0 through 4.0 (at the time of this writing) in this Stack Overflow thread. The required registry keys are quite similar for most .NET Framework versions except 1.0. We’ll ignore that version which has been obsoleted by 1.1 anyway.

Version 4.5 is somewhat tricky since it installs as an in-place update for version 4.0 and reuses the exact same registry keys. The MSDN page How to: Determine Which .NET Framework Versions Are Installed suggests checking for the presence of DWORD value Release, so that’s what I’m doing below. An alternative would be to examine the REG_SZ value Version which equals 4.0.30319 for .NET 4.0 and 4.5.50709 for .NET 4.5.

The Script

In the following Inno Setup scripting code block, function IsDotNetDetected checks whether the specified .NET Framework version and at least the specified service pack level are installed. All listed version strings are for final release versions; betas and release candidates typically have different version numbers. Function InitializeSetup demonstrates how to use IsDotNetDetected to check for .NET Framework 4.0 Client Profile without service packs.

I’m placing this small bit of code in the public domain, so you may embed it in your own projects as you see fit.

[Code]
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
//    ‘v4.5‘          .NET Framework 4.5
//
// 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
var
    key: string;
    install, release, serviceCount: cardinal;
    check45, success: boolean;
begin
    // .NET 4.5 installs as update to .NET 4.0 Full
    if version = ‘v4.5‘ then begin
        version := ‘v4\Full‘;
        check45 := true;
    end else
        check45 := false;

    // installation key group for all .NET versions
    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/4.5 uses value Servicing instead of SP
    if Pos(‘v4‘, version) = 1 then begin
        success := success and RegQueryDWordValue(HKLM, key, ‘Servicing‘, serviceCount);
    end else begin
        success := success and RegQueryDWordValue(HKLM, key, ‘SP‘, serviceCount);
    end;

    // .NET 4.5 uses additional value Release
    if check45 then begin
        success := success and RegQueryDWordValue(HKLM, key, ‘Release‘, release);
        success := success and (release >= 378389);
    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;

Published in DotNet on 2010-04-19. Last edited on 2012-09-26. See latest weblog entry.

时间: 2024-12-18 03:59:16

Check .NET Version with Inno Setup的相关文章

INNO setup 制作安装包

1.获取SQLserver安装路径vardbpath:string;rtn:boolean;rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWAREMicrosoftMSSQLServerSetup','SQLPath', dbpath);if (!rtn) then dbpath := ExpandConstant('{app}'); 2.获取本机的IP地址ip:string;rtn:boolean; rtn :=RegQueryStri

用Inno Setup制作WEB程序安装包

原文 用Inno Setup制作WEB程序安装包 最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考 看看inno 的脚本 [Setup] AppCopyright=test AppName=test AppVerName=test v2.0 SolidCompression=true OutputDir=OutputOutputBaseFilename=test_setup DefaultDirName={pf}\Lms DefaultGroupName=Lms ;

inno setup介绍及官方网站地址

使 用 笔 记 1.Inno Setup 是什么?Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞争力可能已经超过一些商业的安装程序制作软件.关键功能:★ 支持现在所有正在使用的 32 位 Windows 版本: Windows 95,98,2000,Server 2003,XP,Me,NT 4.0 (不需要服务包). ★ 支持创建单个 EXE 格式的安装程序,使你的程序可以很方便地在网络上发表

Inno Setup怎样创建一个自动申请管理员身份运行的快捷

如果你使用的是 Unicode 版本的 Inno Setup,那么以下是更为专业的解决方法. 这是 mlaan 提及的再一种方法. QUOTE( CodeAutomation3.iss) ; -- CodeAutomation2.iss -- ; ; This script shows how to use IUnknown based COM Automation objects. ; ; REQUIRES UNICODE INNO SETUP! ; ; Note: some unneeded

制作部署安装包:Inno Setup

前一篇尝试Office 2003 VSTO的开发.部署有提到用VS开发一个简单的VSTO程序.打包C/S程序,我首先想到的是VS里自带的Setup Project.很遗憾,VS2012及后面的版本都剔除了Setup Project,改用InstallShield Limited Edition. Setup Project配置起来N麻烦,如:配置完成了之后,一旦修改了项目的东西然后重新生成,只有移除原来定义好的快捷方式.主输出,然后重新设置才能应用修改.而ISLE,对于一些简单的打包,基本上都是

INNO SETUP 5.5.0以上版本中文语言包

1 ; *** Inno Setup version 5.5.0+ Chinese messages *** 2 ; 3 ; To download user-contributed translations of this file, go to: 4 ; http://www.jrsoftware.org/is3rdparty.php 5 ; 6 ; Note: When translating this text, do not add periods (.) to the end of

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

翻译自:http://kynosarges.org/DotNetVersion.html 由 Jordan Russell 写的 Inno Setup 是一个伟大的安装脚本程序,但缺乏一个内置的函数来确定安装在目标机器上的.NET Framework版本.幸运的是,它很容易使用 Pascal 脚本语言来实现这样的功能. 脚本 在下面的 Inno Setup的 脚本代码块,函数 IsDotNetDetected 检查指定的.NET Framework 版本和至少指定的服务包级别是否被安装了.所有列

使用Inno Setup 打包.NET程序,并自动安装.Net Framework

使用Inno Setup 打包.NET程序,并自动安装.Net Framework http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/2405730.html Inno Setup是什么 Inno Setup 是一个windows系统下的安装包制作程序.它是免费的(而且允许免费用于商业用途).官网网站:http://www.jrsoftware.org/ 虽然说.NET 可以使用VS来打包安装包,但可定制化绝对不如Inno Setup

Inno Setup connection to the database and create

原文 Inno Setup connection to the database and create Description: the first half of this program in Inno Setup instance inside there, behind the database backup and restore inside the instance is not easy to find online, I spent a great difficulty sen