gpt4 book ai didi

.net - 使用 NSIS 检查 .NET4.5+

转载 作者:行者123 更新时间:2023-12-03 22:52:18 25 4
gpt4 key购买 nike

所有,我知道以下方法可以检查 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

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

NSIS Installer with .NET 4.5

它使用注册表路径/条目“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP”进行检查。现在这也可以让机器人工作,因为条目不会从 .NET4.0 更改为 4.5。我注意到有一个名为 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319\SKUs.NETFramework,Version=v4.5' 的条目,我可以使用它来检查框架版本吗?

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

谢谢你的时间。

注意:随后我的用户执行的一些 .NET4.5 安装具有以下注册表值
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 

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

最佳答案

是的,有一种官方方法可以检查是否安装了 .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.

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


这意味着您首先必须检查是否安装了 4.0,然后检查是否存在名为 Release 的值。在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full ,如果是这样,则 4.5 已经安装(我认为您可以跳过对预发布版本的检查)。
编辑:检查 this post这里是关于检测旧安装的 .NET 版本的详细信息和这个 MSDN article以区分 4.5.x 版本。

关于.net - 使用 NSIS 检查 .NET4.5+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15227634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com