最近用到nsis打包程序,由于程序依赖于Microsoft VC++ 2015 Redistributable,所以安装前需要读注册表判断一下是否需要安装依赖。
上网了解了一些nsis script的基本语法,网上比较多的判断程序都是:
Function InstallX86
Push $R0
ClearErrors
ReadRegDword $R0 HKLM "SOFTWARE\Classes\Installer\Dependencies\{e2495eb6-cca8-47aa-91ea-3410ca44d7b7}" "Version"
IfErrors 0 VSRedistInstalled
MessageBox MB_ICONQUESTION|MB_YESNO "Need MS VC++ 2008 Redistributable, do you want to install it ?" IDNO VSRedistInstalled
File "..\Output\Setup-Files\vcredist_x86.exe"
ExecWait "$INSTDIR\vcredist_x86.exe"
VSRedistInstalled:
Exch $R0
FunctionEnd
我在本地可以正确读出注册表数据,可是ifErrors每次判断都是false,所以每次都会询问是否安装
Need MS VC++ 2008 Redistributable, do you want to install it ?
困惑很久,搜了很多资料,终于找到问题。
ReadRegDword改成ReadRegStr就可以完美运行了,考虑到是读出来的数据是个字符串,存储在Dword类型里产生了错误,至于为什么网上的版本可以work,难道是不同系统的注册表项类型不同?
参考:
http://www.cppblog.com/codejie/archive/2011/04/25/144786.html?opt=admin
http://depa.usst.edu.cn/chenjq/www2/SDesign/ISD/Note2/ViewCommentsNew.asp?id=38
http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed
http://bbs.youkuaiyun.com/topics/360073796