当前位置:  开发笔记 > 开发工具 > 正文

检测程序是否已安装NSIS

如何解决《检测程序是否已安装NSIS》经验,为你挑选了2个好方法。

我正在使用NSIS为程序创建安装程序,检测此程序是否已安装的最佳方法是什么?此外,由于我从autorun.inf运行安装程序,如果它找到已安装的副本,我是否可以立即退出安装程序?有一个更好的方法吗?



1> Magnus Johan..:

这个怎么样.我有一个古老的NSIS剧本.

; Check to see if already installed
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" "UninstallString"
  IfFileExists $R0 +1 NotInstalled
  messagebox::show MB_DEFBUTTON4|MB_TOPMOST "" \
    "0,103" \
    " is already installed." \
    "Launch Uninstall" "Cancel"
    Pop $R1
  StrCmp $R1 2 Quit +1
  Exec $R0
Quit:
  Quit

NotInstalled:


我不得不将`messagebox :: show`行改为`MessageBox MB_YESNO'已安装$ {YOUR_APP_NAME}.卸载现有版本?"/SD IDYES IDNO Quit`.

2> David Hanak..:

我一直在使用稍微复杂的测试,它也检查已安装软件的版本:

!define PRODUCT_VERSION "1.2.0"

!include "WordFunc.nsh"
  !insertmacro VersionCompare

Var UNINSTALL_OLD_VERSION

...

Section "Core System" CoreSystem
  StrCmp $UNINSTALL_OLD_VERSION "" core.files
  ExecWait '$UNINSTALL_OLD_VERSION'

core.files:

  ...
  WriteRegStr HKLM "Software\${PRODUCT_REG_KEY}" "" $INSTDIR
  WriteRegStr HKLM "Software\${PRODUCT_REG_KEY}" "Version" "${PRODUCT_VERSION}"
  ...
SectionEnd

...

Function .onInit
  ;Check earlier installation
  ClearErrors
  ReadRegStr $0 HKLM "Software\${PRODUCT_REG_KEY}" "Version"
  IfErrors init.uninst ; older versions might not have "Version" string set
  ${VersionCompare} $0 ${PRODUCT_VERSION} $1
  IntCmp $1 2 init.uninst
    MessageBox MB_YESNO|MB_ICONQUESTION "${PRODUCT_NAME} version $0 seems to be already installed on your system.$\nWould you like to proceed with the installation of version ${PRODUCT_VERSION}?" \
        IDYES init.uninst
    Quit

init.uninst:
  ClearErrors
  ReadRegStr $0 HKLM "Software\${PRODUCT_REG_KEY}" ""
  IfErrors init.done
  StrCpy $UNINSTALL_OLD_VERSION '"$0\uninstall.exe" /S _?=$0'

init.done:
FunctionEnd

你当然要填写细节,这只会给你一个粗略的骨架.

推荐阅读
周扒pi
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有