Inno Setup:Checking .NET Framework versions


In installers for programs which are using .NET Framework it is necessary to perform a check before installation if .NET Framework is installed on the machine. Such checks are not difficult and, actually they are checks of some keys in registry. These registry keys depend on .NET Framework version.

If .NET Framework is not installed, you need to install it. We prefer opening browser with appropriate URL in order user can download and install .NET Framework. Another way is to include .NET Framework installer into the main installer of the program, it may be convenient but of course this increases size of installer significantly.

Now let’s turn to the code. Here is the check for .NET Framework 3.0:

[CustomMessages]
en.dotnetmissing=Our program needs Microsoft .NET Framework 3.0. Would you like to download and install it now?
[Code]
function InitializeSetup(): Boolean;
var
    ErrorCode: Integer;
    netFrameWorkInstalled : Boolean;
    isInstalled: Cardinal;
begin
    result := true;
    isInstalled := 0;
    netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup',
  'InstallSuccess', isInstalled);
    if ((netFrameworkInstalled)  and (isInstalled <> 1)) then netFrameworkInstalled := false;   
    if netFrameworkInstalled = false then
    begin
        if (MsgBox(ExpandConstant('{cm:dotnetmissing}'),
            mbConfirmation, MB_YESNO) = idYes) then
        begin
          ShellExec('open',
          'http://www.microsoft.com/downloads/details.aspx?familyid=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en',
          '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
        end;
        result := false;
    end;
end;

Here is the same code for .NET Framework 4 Client Profile.

[CustomMessages]
dotnetmissing=Our program needs Microsoft .NET Framework 4.0 Client Profile. Would you like to download and install it now?
[Code]
function InitializeSetup(): Boolean;
var
    ErrorCode: Integer;
    netFrameWorkInstalled : Boolean;
    isInstalled: Cardinal;
begin
    result := true;

  isInstalled := 0;
    netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\client',
  'Install', isInstalled);
    if ((netFrameworkInstalled)  and (isInstalled <> 1)) then netFrameworkInstalled := false;

    if netFrameworkInstalled = false then
    begin
        if (MsgBox(ExpandConstant('{cm:dotnetmissing}'),
            mbConfirmation, MB_YESNO) = idYes) then
        begin
          ShellExec('open',
          'http://download.microsoft.com/download/7/B/6/7B629E05-399A-4A92-B5BC-484C74B5124B/dotNetFx40_Client_setup.exe',
          '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
        end;
        result := false;
    end;
end;

So comparing functions for two versions of .NET Framework we notice that they are differing only in messages, download URLs and registry keys. If necessary, you can simply make general function for several versions of .NET Framework.

http://blog.elangroup-software.com/search?updated-min=2012-01-01T00:00:00%2B04:00&updated-max=2013-01-01T00:00:00%2B04:00&max-results=7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值