在安装软件之前,我需要检查是否安装了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
答案 0 :(得分:1)
简单版本,使用“版本”字符串键和字符串比较。
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可再发行组件,却什么也没做。
答案 1 :(得分:0)
!include LogicLib.nsh
!macro _RegKeyExistsIn _key _pack _t _f
DetailPrint '${_key} ${_pack}'
!insertmacro _LOGICLIB_TEMP
!ifndef _RegKeyExistsIn_var
!define _RegKeyExistsIn_var
Var /Global _RegKeyExistsIn
!endif
StrCpy $_RegKeyExistsIn 0
SetErrors
EnumRegKey $_LOGICLIB_TEMP ${_pack} $_RegKeyExistsIn
IntOp $_RegKeyExistsIn $_RegKeyExistsIn + 1
StrCmp $_LOGICLIB_TEMP "" +3
StrCmp $_LOGICLIB_TEMP "${_key}" "" -3
ClearErrors
IfErrors `${_f}` `${_t}`
!macroend
Section
${If} "Dependents{67f67547-9693-4937-aa13-56e296bd40f6}" RegKeyExistsIn 'HKCR "Installer\Dependencies\VC,redist.x86,x86,14.16,bundle"'
DetailPrint "Found the key"
${Else}
DetailPrint "Key does not exist"
${EndIf}
SectionEnd
但是我不知道这是否是检测可再发行文件的最佳方法,因为您正在检查特定的次要版本和一些未知的GUID。
documentation说,您应该检查HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ VisualStudio \%vs-version%\ VC \ Runtimes \%x86 | x64 | ARM%:
!include LogicLib.nsh
!ifmacrondef _VerCheck2=>
!macro _VerCheck2_geq_imp l1 l2 r1 r2 _t _f
!insertmacro _LOGICLIB_TEMP
!define _VerCheck2_geq_imp _VerCheck2_geq_${__COUNTER__}
StrCpy $_LOGICLIB_TEMP 0
IntCmpU ${l1} ${r1} ${_VerCheck2_geq_imp}eq "" ${_VerCheck2_geq_imp}end
StrCpy $_LOGICLIB_TEMP 1
Goto ${_VerCheck2_geq_imp}end
${_VerCheck2_geq_imp}eq:
IntCmpU ${l2} ${r2} "" "" ${_VerCheck2_geq_imp}end
StrCpy $_LOGICLIB_TEMP 1
${_VerCheck2_geq_imp}end:
!undef _VerCheck2_geq_imp
!insertmacro _= $_LOGICLIB_TEMP 0 `${_f}` `${_t}`
!macroend
!macro _VerCheck2=> _lhs _rhs _t _f
!insertmacro _VerCheck2_geq_imp ${_lhs} ${_rhs} `${_f}` `${_t}`
!macroend
!endif
Section
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "Installed"
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "MajorVersion"
ReadRegDWORD $2 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "MinorVersion"
${If} $0 <> 0
DetailPrint "Found version $1.$2"
${If} "$1 $2" VerCheck2=> "14 16"
DetailPrint "The installed version is usable"
${Else}
DetailPrint "Must install redist"
${EndIf}
${Else}
DetailPrint "Must install redist"
${EndIf}
SectionEnd
答案 2 :(得分:0)
另一种正确的方法(并且被许多开发人员推荐)是简单地静默安装运行系统。
它不会损害任何组件或软件,并且更快,更容易。