gpt4 book ai didi

nsis - 如何使用 NSIS 检查是否安装了 Visual C++ 2017 可再发行组件 x86

转载 作者:行者123 更新时间:2023-12-03 23:53:11 43 4
gpt4 key购买 nike

在安装软件之前,我需要检查 Visual C++ 2017 redistributable(x86)是否安装。如果未安装,则在先安装软件时,我可以安装可再发行可执行文件。

当我手动安装它时,它显示在以下路径中:

Computer\HKEY_CLASSES_ROOT\Installer\Dependencies\VC,redist.x86,x86,14.16,bundle\Dependents\{67f67547-9693-4937-aa13-56e296bd40f6}

请帮助我如何使用 NSIS 检查上述路径?

因此,如果在安装软件之前不存在可执行文件,我可以使用以下代码进行安装:
!insertmacro MUI_LANGUAGE "English"

Section "MyApp"

SetOutPath $INSTDIR
File "\Desktop\Common\vcredist_x86.exe"

ExecShell "" "$INSTDIR\vcredist_x86.exe"
SectionEnd

最佳答案

更简单的版本,使用“版本”字符串键和字符串比较。

Section "CheckVCRedist"
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "Version"
DetailPrint "Found version $0"
; Check for 14.16.27027 [sic]
${If} $0 >= "v14.16.27024.01"
DetailPrint "The installed version is usable"
${Else}
DetailPrint "Must install redist"
${EndIf}
SectionEnd

缺点:如果安装了“v14.100.x.y”,理论上这可能会产生误报。但影响只会是您尝试安装 14.16 可再发行组件,它什么也不做。

[编辑]
奖励代码:如果您构建 vswhere ,您可以使用它从 Visual C++ 安装目录中提取可再发行组件:
Section /o VCRedist VCRedist_id
; Use the "pluginsdir"; it's really the NSIS temp dir, and it's cleaned up at the end.
InitPluginsDir
SetOutPath "$pluginsdir"

; Finding the correct redistributable is a bit of a problem. MSVC itself ships with an
; appropriate redistributable. It's location will likely be similar to
; C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.16.27012
; but the exact location of the Redist folder can differ. That's why vswhere.exe is used.
; Note that the vswhere used is the local one, NOT the one from
; Visual Studio itself (finding that would be a chicken-and-egg problem). This version
; is new enough to support the -find parameter, which is what we need to find the
; redistributable. Stuff the result in a temporary redist.path file.
!system 'vswhere.exe -latest -find "VC/Redist/**/vc_redist.x64.exe" > redist.path'
!define /file REDISTPATH redist.path
; Check what version we found. This is used to decide at install time whether we need to
; unpack this redistributable.
!getdllversion "${REDISTPATH}" RedistVer
!echo "Including VC++ Redistributable Version ${RedistVer1}.${RedistVer2}.${RedistVer3}.${RedistVer4}"

SetCompress off
File "${REDISTPATH}"
SetCompress auto

; Cleanup the temporary redist.path file which held the output of vswhere -find
!system 'del redist.path'

ExecWait "vc_redist.x64.exe"
SectionEnd

请注意,该部分是可选的,它是使用之前详述的测试有条件地启用的:
Function VCRedistNeeded
SetRegView 64
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Version"
DetailPrint "Found version $0"
${If} $0 >= "v${RedistVer1}.${RedistVer2}.${RedistVer3}.${RedistVer4}"
DetailPrint "VC++ redistributable already present"
${Else}
DetailPrint "Installing VC++ redistributable."
SectionSetFlags ${VCRedist_id} 1 ; Selected
${EndIf}
FunctionEnd

关于nsis - 如何使用 NSIS 检查是否安装了 Visual C++ 2017 可再发行组件 x86,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54390195/

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