使用 NSIS 检查 .NET4.5+ [英] Check for .NET4.5+ with NSIS

查看:50
本文介绍了使用 NSIS 检查 .NET4.5+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,我知道以下方法可以检查 NSIS 中的框架版本.对于 .NET4.0+ 我目前使用

All, I am aware of the following methods to check the framework version in NSIS. For .NET4.0+ I currently use

Function IsDotNetInstalled

    StrCpy $0 "0"
    StrCpy $1 "SOFTWAREMicrosoft.NETFramework" ; Registry entry to look in.
    StrCpy $2 0

    StartEnum:
    ; Enumerate the versions installed.
    EnumRegKey $3 HKLM "$1policy" $2

    ; If we don't find any versions installed, it's not here.
    StrCmp $3 "" noDotNet notEmpty

    ; We found something.
    notEmpty:
        ; Find out if the RegKey starts with 'v'.  
        ; If it doesn't, goto the next key.
        StrCpy $4 $3 1 0
        StrCmp $4 "v" +1 goNext
        StrCpy $4 $3 1 1

        ; It starts with 'v'.  Now check to see how the installed major version
        ; relates to our required major version.
        ; If it's equal check the minor version, if it's greater, 
        ; we found a good RegKey.
        IntCmp $4 ${DOT_MAJOR} +1 goNext yesDotNetReg
        ; Check the minor version.  If it's equal or greater to our requested 
        ; version then we're good.
        StrCpy $4 $3 1 3
        IntCmp $4 ${DOT_MINOR} yesDotNetReg goNext yesDotNetReg

    goNext:
        ; Go to the next RegKey.
        IntOp $2 $2 + 1
        goto StartEnum

    yesDotNetReg:
        ; Now that we've found a good RegKey, let's make sure it's actually
        ; installed by getting the install path and checking to see if the 
        ; mscorlib.dll exists.
        EnumRegValue $2 HKLM "$1policy$3" 0
        ; $2 should equal whatever comes after the major and minor versions 
        ; (ie, v1.1.4322)
        StrCmp $2 "" noDotNet
        ReadRegStr $4 HKLM $1 "InstallRoot"
        ; Hopefully the install root isn't empty.
        StrCmp $4 "" noDotNet
        ; Build the actuall directory path to mscorlib.dll.
        StrCpy $4 "$4$3.$2mscorlib.dll"
        IfFileExists $4 yesDotNet noDotNet

    noDotNet:
        ; No, something went wrong along the way.  Looks like the 
        ; proper .NET Framework isn't installed.  
        MessageBox MB_ICONEXCLAMATION "To install UserCost, Microsoft's .NET Framework v${DOT_MAJOR}.${DOT_MINOR} 
        (or higher) must be installed. Cannot proceed with the installation!"
        ${OpenURL} "${WWW_MS_DOTNET4}"
        Abort

    yesDotNet:
        ; Everything checks out. Proceed with the rest of the installation.

FunctionEnd

这对于 .NET4.0 非常有效,但我现在扩展了我的应用程序以利用 async/await 功能,随后需要用户安装 .NET4.5+.上述方法不适合,因为 .NET4.5 的安装现在不使用注册路径HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkPolicy"来存储任何新信息,即该路径似乎不包含一个值.NET4.0 和 4.5 之间的变化.现在我看到了以下帖子:

This works very well for .NET4.0, but I have now extended my application to utilise the async/await features and subsequently need users to install .NET4.5+. The above method is not suitable as the installation for .NET4.5 now does not use the regestry path 'HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkPolicy" to store any new information, that is that path does not seem to hold a value that changes between .NET4.0 and 4.5. Now I have seen the following posts:

带有 .NET 4.5 的 NSIS 安装程序

它使用注册表路径/条目HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDP"来进行检查.现在这也可以 bot 工作,因为条目不会从 .NET4.0 更改为 4.5.我注意到有一个名为 'HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkv4.0.30319SKUs.NETFramework,Version=v4.5' 的条目,我可以使用它来检查框架版本吗?

which uses the registry path/entry 'HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDP' to do the checks. Now this also does bot work as the entry does not change from .NET4.0 to 4.5. I notice that there is and entry called 'HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkv4.0.30319SKUs.NETFramework,Version=v4.5' can I use this to check the Framework version invariably?

是否有使用 NSIS 检查 .NET4.5 的官方方法?

Is there an offical line of the way to check for .NET4.5 using NSIS?

感谢您的时间.

注意:随后我的用户执行的一些 .NET4.5 安装具有

HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4Full 

名为 Release 的 DWORD 值不是 378389 而是 378181.进行此更改似乎解决了问题,因为 Release 的条目不在 .NET4.5 及以下版本的注册表中.

a DWORD value named Release was not 378389 but 378181. Making this change seemed to resolve the problem as the entry for the Release is not in the registry for .NET4.5 and below.

推荐答案

是的,有一种官方方法可以检查是否安装了 .NET Framework 4.5,即使它不是很友好.来自 MSDN:

Yes there is an official way to check if .NET Framework 4.5 is installed, even if it's not really friendly. From MSDN:

您可以通过检查注册表中的 HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4Full 子项来测试是否安装了 .NET Framework 4.5 或 .NET Framework 4一个名为 ReleaseDWORD 值.此 DWORD 的存在表明该计算机上已安装 .NET Framework 4.5.Release 的值是一个版本号.要确定是否安装了 .NET Framework 4.5 的最终发行版,请检查等于或大于 378389 的值.

You can test whether the .NET Framework 4.5 or the .NET Framework 4 is installed by checking the HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4Full subkey in the registry for a DWORD value named Release. The existence of this DWORD indicates that the .NET Framework 4.5 has been installed on that computer. The value of Release is a version number. To determine if the final release version of the .NET Framework 4.5 is installed, check for a value that is equal to or greater than 378389.

http://msdn.microsoft.com/en-us/library/hh925568.aspx

这意味着您首先必须检查是否安装了 4.0,然后检查 HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4 中是否有名为 Release 的值完整,如果是,那么 4.5 已经安装(我认为你可以跳过对预发布版本的检查).

It means you first have to check if 4.0 is installed and then to check if there is a value named Release in HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4Full, if so then 4.5 is already installed (I think you can skip the check for a pre-release version).

检查 这篇文章 在这里关于检测旧安装的 .NET 版本的详细信息和这个 MSDN 文章来区分 4.5.x 版本.

check this post here on SO for details about detecting older installed .NET versions and this MSDN article to distinguish between for 4.5.x versions.

这篇关于使用 NSIS 检查 .NET4.5+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆