NSIS在某些x64操作系统上没有检测到以前的版本

时间:2015-12-08 22:14:31

标签: nsis

我在安装新版本之前强制卸载以前的版本 出于某种原因,它不适用于XP / Vista / 10 x64。卸载字符串为空。我几乎肯定它正在寻找错误的注册表。有没有办法强迫它检查非wow64(反之亦然)?我不知道它还有什么可能。

# The ExecWait seems not to work on Windows XP x64/Vista x64/10 x64 (it seems to work fine on Vista x64/8 x64)
${If} ${RunningX64}
   ${GetWindowsVersion} $R0
   ReadRegStr $R1 HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString"
   MessageBox MB_OK "You are running $R0 x64!  R1 is $R1"
   StrCmp $R1 "" no_remove_uninstaller
${Else}
  ${GetWindowsVersion} $R0
  ReadRegStr $R1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString"
  MessageBox MB_OK "You are running $R0 x86!  R1 is $R1"
  StrCmp $R1 "" no_remove_uninstaller
${EndIf}

  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  "${PRODUCT_LONG_NAME} is already installed. $\n$\nIf you have software older than XXX 1.3, please manually uninstall it with Windows before proceeding. $\n$\nClick `OK` to remove the \
  previous version or `Cancel` to cancel this upgrade." \
  IDOK uninst IDCANCEL giveup

giveup:
  Abort

#  Run the uninstaller
uninst:
   ExecWait '"$INSTDIR\uninst.exe" _?=$INSTDIR' $R1
   StrCmp $R1 0 no_remove_uninstaller # Success? If so we are done...
   Abort # Uninstaller was canceled or failed, we cannot continue

已编辑 - 我删除了上面的x64功能。并提出了你提到的变化。由于缺少InstallString,我使用filefunc getparent函数进行测试。应该这样做还是我还需要继续进行regview?它似乎适用于XP x86和7 x64,尽管它们总是有效。这使得操作系统之间的错误很奇怪。

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString"
${GetParent} $0 $R0
IfFileExists "$R0\uninst.exe" 0 no_remove_uninstaller
ExecWait '"$R0\uninst.exe" _?=$R0' $R1
StrCmp 0 $R1 0 giveup
Delete "$R0\uninst.exe"
RMDir "$R0"

其他更新:它仍无法在Vista x64和XP x64上运行。其他版本的Windows现在都可以使用。

上次更新我认为它现在有效...我从regview 64换了32因为我对我正在做的事情的思考被逆转了。

1 个答案:

答案 0 :(得分:1)

你的代码没有意义。

您正在检查${RunningX64},但仍然强制它访问注册表的32位部分。除非使用SetRegView 64,否则32位安装程序将始终从注册表的32位部分读取。

更大的问题是,在运行以前版本的卸载程序时,必须使用以前的版本路径,而不是$ InstDir!如果旧版本编写InstallLocation值,则可以使用该值,否则必须从UninstallString值中提取路径。重要的是要记住以前的安装可能与您最终安装的目录不同,因此您还必须进行一些额外的清理:

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "InstallLocation"
IfFileExists "$0\uninst.exe" 0 no_previous_version
ExecWait '"$0\uninst.exe" _?=$0' $R1
StrCmp 0 $R1 0 uninst_aborted
Delete "$0\uninst.exe"
RMDir "$0"