热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用NSIS检查.NET4.5+。-Checkfor.NET4.5+withNSIS

All,IamawareofthefollowingmethodstochecktheframeworkversioninNSIS.For.NET4.0+Icurr

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

所有这些,我都知道下面的方法来检查NSIS中的框架版本。对于我目前使用的。net4.0 +

Function IsDotNetInstalled

    StrCpy $0 "0"
    StrCpy $1 "SOFTWARE\Microsoft\.NETFramework" ; Registry entry to look in.
    StrCpy $2 0

    StartEnum:
    ; Enumerate the versions installed.
    EnumRegKey $3 HKLM "$1\policy" $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 "$1\policy\$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.$2\mscorlib.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

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_MACHINE\SOFTWARE\Microsoft.NETFramework\Policy" 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:

这对于. net4.0来说工作得很好,但是我现在扩展了我的应用程序来使用异步/ wait特性,然后需要用户安装. net4.5 +。以上方法不适用于. net4.5的安装,现在不使用regestry路径'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft '。NETFramework\策略“存储任何新信息,即路径似乎不包含在. net4.0和4.5之间变化的值。现在我看到以下的帖子:

NSIS Installer with .NET 4.5

NSIS安装与。net 4.5

which uses the registry path/entry 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP' 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_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319\SKUs.NETFramework,Version=v4.5' can I use this to check the Framework version invariably?

使用注册表路径/入口'HKEY_LOCAL_MACHINE\软件\Microsoft\NET Framework Setup\NDP'进行检查。现在,由于条目没有从. net4.0更改为4.5,这也使得bot起作用。我注意到有一个条目叫做“HKEY_LOCAL_MACHINE\ microsoft.\ netframework \v4.0.30319\SKUs.NETFramework,Version=v4.5”,我是否可以用这个来检查框架版本?

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

使用NSIS检查.NET4.5是否有一种越界的方法?

Thanks for your time.

谢谢你的时间。


Note: subsequently some installation of .NET4.5 my users have performed have had registry values for

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

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 

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.

名为Release的DWORD值不是378389而是378181。这样做似乎解决了问题,因为发布的条目不在. net4.5和以下的注册表中。

6 个解决方案

#1


23  

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

是的,有一个官方的方法来检查。net Framework 4.5是否已经安装,即使它不是很友好。从MSDN:

You can test whether the .NET Framework 4.5 or the .NET Framework 4 is installed by checking the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 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.

您可以通过检查注册中心的HKEY_LOCAL_MACHINE\软件\Microsoft\NET Framework Setup\NDP\v4\ v4\ v4\完整子键来测试.NET Framework 4.5或.NET Framework 4是否已安装。这个DWORD的存在表明。net Framework 4.5已经安装在那台计算机上。发布的值是版本号。要确定是否安装了. net Framework 4.5的最终版本,请检查是否为等于或大于378389的值。

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

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

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_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full, if so then 4.5 is already installed (I think you can skip the check for a pre-release version).

这意味着您首先要检查是否安装了4.0,然后再检查在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\ NDP\v4 Full中是否有一个名为Release的值(如果已经安装了的话)(我认为您可以跳过对预发布版本的检查)。

EDIT: 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.

编辑:查看这篇文章,以便了解关于检测较早安装的。net版本和MSDN文章以区分4.5版本的细节。x版本。

#2


5  

Here is a function that I wrote that checks for, and downloads if needed, .NET 4.5. In addition, the code also looks for a local copy of the .NET installer - in case you were to put your installer onto a CD or USB drive or something. Supports Silent and Non-Silent installs, as well as setting the Reboot flag. The function is self-contained, but expects you to include LogicLib (which is included with the basic NSIS install).

这是我编写的一个函数,用于检查。net 4.5,如果需要,可以下载。此外,代码还会寻找。net安装程序的本地副本——如果你要把你的安装程序放到CD或USB驱动器或其他东西上的话。支持静默和非静默安装,以及设置重新引导标志。该函数是自包含的,但是期望您包含LogicLib(它包含在基本的NSIS安装中)。

This is the code that I wrote for what will be the installer for my Rachel's Story books.

这是我为《瑞秋的故事》写的代码。

Function CheckAndDownloadDotNet45
# Let's see if the user has the .NET Framework 4.5 installed on their system or not
# Remember: you need Vista SP2 or 7 SP1.  It is built in to Windows 8, and not needed
# In case you're wondering, running this code on Windows 8 will correctly return is_equal
# or is_greater (maybe Microsoft releases .NET 4.5 SP1 for example)

# Set up our Variables
Var /GLOBAL dotNET45IsThere
Var /GLOBAL dotNET_CMD_LINE
Var /GLOBAL EXIT_CODE

ReadRegDWORD $dotNET45IsThere HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
IntCmp $dotNET45IsThere 378389 is_equal is_less is_greater

is_equal:
    Goto done_compare_not_needed
is_greater:
    # Useful if, for example, Microsoft releases .NET 4.5 SP1
    # We want to be able to simply skip install since it's not
    # needed on this system
    Goto done_compare_not_needed
is_less:
    Goto done_compare_needed

done_compare_needed:
    #.NET Framework 4.5 install is *NEEDED*

    # Microsoft Download Center EXE:
    # Web Bootstrapper: http://go.microsoft.com/fwlink/?LinkId=225704
    # Full Download: http://go.microsoft.com/fwlink/?LinkId=225702

    # Setup looks for components\dotNET45Full.exe relative to the install EXE location
    # This allows the installer to be placed on a USB stick (for computers without internet connections)
    # If the .NET Framework 4.5 installer is *NOT* found, Setup will connect to Microsoft's website
    # and download it for you

    # Reboot Required with these Exit Codes:
    # 1641 or 3010

    # Command Line Switches:
    # /showrmui /passive /norestart

    # Silent Command Line Switches:
    # /q /norestart


    # Let's see if the user is doing a Silent install or not
    IfSilent is_quiet is_not_quiet

    is_quiet:
        StrCpy $dotNET_CMD_LINE "/q /norestart"
        Goto LookForLocalFile
    is_not_quiet:
        StrCpy $dotNET_CMD_LINE "/showrmui /passive /norestart"
        Goto LookForLocalFile

    LookForLocalFile:
        # Let's see if the user stored the Full Installer
        IfFileExists "$EXEPATH\components\dotNET45Full.exe" do_local_install do_network_install

        do_local_install:
            # .NET Framework found on the local disk.  Use this copy

            ExecWait '"$EXEPATH\components\dotNET45Full.exe" $dotNET_CMD_LINE' $EXIT_CODE
            Goto is_reboot_requested

        # Now, let's Download the .NET
        do_network_install:

            Var /GLOBAL dotNetDidDownload
            NSISdl::download "http://go.microsoft.com/fwlink/?LinkId=225704" "$TEMP\dotNET45Web.exe" $dotNetDidDownload

            StrCmp $dotNetDidDownload success fail
            success:
                ExecWait '"$TEMP\dotNET45Web.exe" $dotNET_CMD_LINE' $EXIT_CODE
                Goto is_reboot_requested

            fail:
                MessageBox MB_OK|MB_ICONEXCLAMATION "Unable to download .NET Framework.  ${PRODUCT_NAME} will be installed, but will not function without the Framework!"
                Goto done_dotNET_function

            # $EXIT_CODE contains the return codes.  1641 and 3010 means a Reboot has been requested
            is_reboot_requested:
                ${If} $EXIT_CODE = 1641
                ${OrIf} $EXIT_CODE = 3010
                    SetRebootFlag true
                ${EndIf}

done_compare_not_needed:
    # Done dotNET Install
    Goto done_dotNET_function

#exit the function
done_dotNET_function:

FunctionEnd

#3


4  

In the end I went with the following function which utilises the answer above. This method first creates a directory "$INSTDIR\dotNETFramework" which contains the .NET web installer:

最后我使用了下面的函数,它利用了上面的答案。此方法首先创建一个目录“$INSTDIR\dotNETFramework”,其中包含.NET web安装程序:

Function CheckAndInstallDotNet
    ; Installer dotNetFx45_Full_setup.exe avalible from http://msdn.microsoft.com/en-us/library/5a4x27ek.aspx
    ; Magic numbers from http://msdn.microsoft.com/en-us/library/ee942965.aspx
    ClearErrors
    ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
    IfErrors NotDetected
    ${If} $0 >= 378389
        DetailPrint "Microsoft .NET Framework 4.5 is installed ($0)"
    ${Else}
    NotDetected:
        MessageBox MB_YESNO|MB_ICONQUESTION ".NET Framework 4.5+ is required for ProgramX2013, \
            do you want to launch the web installer? This requires a valid internet connection." IDYES InstallDotNet IDNO Cancel 
        Cancel:
            MessageBox MB_ICONEXCLAMATION "To install ProgramX, Microsoft's .NET Framework v${DOT_MAJOR}.${DOT_MINOR} \
                (or higher) must be installed. Cannot proceed with the installation!"
            ${OpenURL} "${WWW_MS_DOTNET4_5}"
            RMDir /r "$INSTDIR" 
            SetOutPath "$PROGRAMFILES"
            RMDir "$INSTDIR" 
            Abort

        ; Install .NET4.5.
        InstallDotNet:
            DetailPrint "Installing Microsoft .NET Framework 4.5"
            SetDetailsPrint listonly
            ExecWait '"$INSTDIR\dotNETFramework\dotNetFx45_Full_setup.exe" /passive /norestart' $0
            ${If} $0 == 3010 
            ${OrIf} $0 == 1641
                DetailPrint "Microsoft .NET Framework 4.5 installer requested reboot."
                SetRebootFlag true 
            ${EndIf}
            SetDetailsPrint lastused
            DetailPrint "Microsoft .NET Framework 4.5 installer returned $0"
    ${EndIf}

    ; Now remove the dotNETFramework directory and contents.
    RMDir /r "$INSTDIR\dotNETFramework" 
FunctionEnd

This method seemlessley launches the .NET4.5 installer if there is an internet connection and returns after the installation is complete.

如果有internet连接,这个方法会启动. net4.5安装程序,并在安装完成后返回。

I hope this helps someone else.

我希望这能帮助别人。

#4


2  

Here's a simple NSIS Function that checks for .NET versions (works for 4.5, 4.5.1, 4.5.2 and 4.6). The numeric comparisons are based on MSDN.

这里有一个简单的NSIS函数,用于检查。net版本(适用于4.5、4.5.1、4.5.2和4.6)。数值比较基于MSDN。

Place the function in your NSIS file and invoke it like so

将函数放在NSIS文件中,并像这样调用它

Call CheckForDotVersion45Up
Pop $0
DetailPrint $0

Here is the function.

这是函数。

; returns a numeric value on the stack, ranging from 0 to 450, 451, 452 or 460. 0 means nothing found, the other values mean at least that version
Function CheckForDotVersion45Up

  ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" Release

  IntCmp $0 393295 is46 isbelow46 is46

  isbelow46:
  IntCmp $0 379893 is452 isbelow452 is452

  isbelow452:
  IntCmp $0 378675 is451 isbelow451 is451

  isbelow451:
  IntCmp $0 378389 is45 isbelow45 is45

  isbelow45:
  Push 0
  Return

  is46:
  Push 460
  Return

  is452:
  Push 452
  Return

  is451:
  Push 451
  Return

  is45:
  Push 45
  Return

FunctionEnd

#5


1  

Now that .NET Framework 4.5.1 is available the actual value of DWORD named Release in the registry needs to be checked, not just its existence.

既然。net Framework 4.5.1已经可用,那么需要检查注册中心中名为Release的DWORD的实际值,而不仅仅是它的存在。

A value of 378758 means that .NET Framework 4.5.1 is installed, however, as described here this value is 378675 on Windows 8.1.

然而,值378758意味着安装了。net Framework 4.5.1,正如这里描述的,这个值在Windows 8.1上是378675。

#6


0  

If you're looking for options with .net framework 4.0+ (and above) including

如果您正在寻找。net framework 4.0+(及以上版本)的选项,包括

  • .net 4.5
  • net 4.5
  • .net 4.5.1
  • net 4.5.1

you can also check this plug-in for NSIS: DotNetChecker

您还可以为NSIS: DotNetChecker检查该插件


推荐阅读
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • 如何搭建Java开发环境并开发WinCE项目
    本文介绍了如何搭建Java开发环境并开发WinCE项目,包括搭建开发环境的步骤和获取SDK的几种方式。同时还解答了一些关于WinCE开发的常见问题。通过阅读本文,您将了解如何使用Java进行嵌入式开发,并能够顺利开发WinCE应用程序。 ... [详细]
  • 如何用JNI技术调用Java接口以及提高Java性能的详解
    本文介绍了如何使用JNI技术调用Java接口,并详细解析了如何通过JNI技术提高Java的性能。同时还讨论了JNI调用Java的private方法、Java开发中使用JNI技术的情况以及使用Java的JNI技术调用C++时的运行效率问题。文章还介绍了JNIEnv类型的使用方法,包括创建Java对象、调用Java对象的方法、获取Java对象的属性等操作。 ... [详细]
  • 本文介绍了一种轻巧方便的工具——集算器,通过使用集算器可以将文本日志变成结构化数据,然后可以使用SQL式查询。集算器利用集算语言的优点,将日志内容结构化为数据表结构,SPL支持直接对结构化的文件进行SQL查询,不再需要安装配置第三方数据库软件。本文还详细介绍了具体的实施过程。 ... [详细]
author-avatar
oo艾丁湖oooo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有