Detecting if a program is already installed with NSIS

前端 未结 4 732
庸人自扰
庸人自扰 2020-12-04 20:42

I\'m using NSIS to create an installer for a program, what is the best way to detect if this program is already installed? Also, since I\'m running the installer from the au

4条回答
  •  没有蜡笔的小新
    2020-12-04 20:59

    After creating your uninstaller create a product name entry in registry

    !define PRODUCT_UNINST_ROOT_KEY "HKLM"
    !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANY_NAME} ${PRODUCT_NAME}"
    Section -Post
      SetShellVarContext current
      WriteUninstaller "${UNINST_PATH}\uninst.exe"
      WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
    

    To see if the product is installed do

    Function IsProductInstalled
      ClearErrors
      ReadRegStr $2 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"  
      StrCmp $2 "" exit
    

    In your uninstall you should be doing

    Section Uninstall
        DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
    

提交回复
热议问题