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-11-03 21:40:31

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

(转)Inno Setup Script Silently install .NET 3.5 and Sql Server Express

Disclaimer: Some of this s-c-r-i-p-t is adapted from an example I found on another website, I have been unable to retrace the original, if you recognise some of this work as your own please contact me and I would be happy to credit you. There are a f

注册flash.ocx inno setup (转)

; 脚本由 Inno Setup 脚本向导 生成!   ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!         #define MyAppName "xx模块"   #define MyAppName2 "xx模块"   #define MyAppName3 "xx系统"   #define MyAppVersion "2012"   #define IncludeFramework true 

用Inno Setup制作WEB程序安装包

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

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 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

Inno Setup 插件 CallbackCtrl V1.1 (回调函数插件)

原文 http://restools.hanzify.org/article.asp?id=101 VC 重现 InnoCallback 的功能. Version 1.1修正在某些 Windows 平台(例如: Windows XP SP3)出现不能正常运行的问题.  引用来自 test1.iss ; -- test.iss --; restools; http://restools.hanzify.org; 时间仓促,如有错误请到我的 BLOG 咨询; CallbackCtrl.dll 为一个

INNO Setup 使用笔记(来自网络)

[Setup] AppName={#MyAppName} AppVerName={#MyAppVerName} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={pf}\My Programee DefaultGroupName={#MyAppName} InfoBeforeFile=D:\In

用Inno Setup来解决.NetFramework安装问题

前段时间朋友接了一个项目,具体是开发一个安装在局域网内的软件,这个 软件会定时连接局域网内的服务器来更新本地客户端的一些信息,因为在局域网 内存在着多种不同的Windows版本,从WindowsXP.Windows2003及Windows2008到 Windows7等,这个软件采用VS2008/.Net Framework2.0开发,因为有些系统默认 没有安装.Net Framework2.0,所以在运行时需要确保客户机上已经安装上.Net Framework2.0,于是想到将软件打包. 制作软

Inno Setup 系统托盘图标插件 TrayIconCtrl V1.5

原文 http://restools.hanzify.org/article.asp?id=93 V1.5 修正在某些 Windows 平台上(例如 Windows XP SP3)不能正常运行的问题.  引用来自 trayiconctrl.iss,2009-10-16 21:06:53 ; -- trayiconctrl.iss --; restools; http://restools.hanzify.org; TrayIconCtrl.dll 为一个用于 Inno Setup 的 15.5