[英]Want to uninstall components conditionally in NSIS script in Uninstall section
I have written Installer and Updater using NSIS script for three different environments(QA,UAT and PROD). 我已经使用NSIS脚本为三种不同的环境(QA,UAT和PROD)编写了Installer和Updater。 Installer is different for all three environments but updater is same. 所有三种环境的安装程序都不同,但更新程序是相同的。 In my old installers uninstaller was not defined and newly updated installer has uninstaller code. 在我的旧安装程序中,未定义卸载程序,并且新更新的安装程序具有卸载程序代码。 Now i want to modify my Updater in such way that it should create uninstaller for all environments which previously installed coz i don't want to run my new installers. 现在我想修改我的更新程序,它应该为以前安装的所有环境创建卸载程序,因为我不想运行我的新安装程序。 I will be running only updated for now. 我现在只会更新。 I have written my uninstaller code in 'Section -post' using 'WriteUninstaller' see the code below. 我使用'WriteUninstaller'在'Section -post'中编写了我的卸载程序代码,请参阅下面的代码。 This code will add three entries to control panel programs list(SSCM). 此代码将向控制面板程序列表(SSCM)添加三个条目。 Now i am facing issue in my 'Section UnInstall' where i want to check which(QA or UAT or PROD) uninstaller is clicked by user from control panel. 现在我在我的'UnInstall'部分面临问题,我想检查用户从控制面板点击了哪个(QA或UAT或PROD)卸载程序。
How should i check which environment is clicked by user? 我该如何检查用户点击了哪个环境? Is it possible in NSIS scripts? 是否可以在NSIS脚本中使用?
My Code: 我的代码:
!define PRODUCT_NAME "Updater name"
!define PRODUCT_NAME_QA "QA Name"
!define PRODUCT_NAME_UAT "UAT Name"
!define PRODUCT_NAME_PROD "PROD Name"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\App.exe"
!define PRODUCT_UNINST_KEY_QA "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_QA}"
!define PRODUCT_UNINST_KEY_UAT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_UAT}"
!define PRODUCT_UNINST_KEY_PROD "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_PROD}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
Section -Post
IfFileExists "$PROGRAMFILES\App Path\QA\app.exe" QAExists PastQACheck
QAExists:
WriteUninstaller "$PROGRAMFILES\App Path\QA\App Uninstall.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$PROGRAMFILES\App Path\QA\App.exe"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_QA}" \
"DisplayName" "App (QA)"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_QA}" \
"UninstallString" "$\"$PROGRAMFILES\App Path\QA\App Uninstall.exe$\""
PastQACheck:
IfFileExists "$PROGRAMFILES\App Path\UAT\app.exe" UATExists PastUATCheck
UATExists:
WriteUninstaller "$PROGRAMFILES\App Path\UAT\App Uninstall.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$PROGRAMFILES\App Path\UAT\App.exe"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_UAT}" \
"DisplayName" "App (UAT)"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_UAT}" \
"UninstallString" "$\"$PROGRAMFILES\App Path\UAT\App Uninstall.exe$\""
PastUATCheck:
IfFileExists "$PROGRAMFILES\App Path\PROD\app.exe" PRODExists PastPRODCheck
PRODExists:
WriteUninstaller "$PROGRAMFILES\App Path\PROD\App Uninstall.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$PROGRAMFILES\App Path\PROD\App.exe"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_PROD}" \
"DisplayName" "App (PROD)"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY_PROD}" \
"UninstallString" "$\"$PROGRAMFILES\App Path\PROD\App Uninstall.exe$\""
PastQACheck:
SectionEnd
Section Uninstall
SetShellVarContext all
;Check if uninstallation called for QA
;Condition to check if user has clicked QA uninstallation
QAExists:
delete "$PROGRAMFILES\App Path\QA\"
delete "$DESKTOP\QA.lnk"
RMDIR "$PROGRAMFILES\App Path\QA\"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY_QA}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
PastQACheck:
;Check if uninstallation called for UAT
;Condition to check if user has clicked UAT uninstallation
UATExists:
delete "$PROGRAMFILES\App Path\UAT\"
delete "$DESKTOP\UAT.lnk"
RMDIR "$PROGRAMFILES\App Path\UAT\"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY_UAT}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
PastUATCheck:
;Check if uninstallation called for PROD
;Condition to check if user has clicked PROD uninstallation
PRODExists:
delete "$PROGRAMFILES\App Path\PROD\"
delete "$DESKTOP\PROD.lnk"
RMDIR "$PROGRAMFILES\App Path\PROD\"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY_PROD}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
PastPRODCheck:
SetAutoClose true
SectionEnd
What conditions to write to check environment for uninstallation? 写入什么条件来检查卸载环境?
When you write the uninstaller you can also use WriteINIStr
to write some extra identification data to a file in the same directory. 编写卸载程序时,还可以使用WriteINIStr
将一些额外的标识数据写入同一目录中的文件。 You can then use something like ReadINIStr $0 "$exedir\\appuninstall.ini" "Data" "Id"
to read the data in the uninstaller. 然后,您可以使用类似ReadINIStr $0 "$exedir\\appuninstall.ini" "Data" "Id"
来读取卸载程序中的数据。
It is also possible to append data to the end of the uninstaller itself: 也可以将数据附加到卸载程序本身的末尾:
Section
WriteUninstaller "$InstDir\Uninst.exe"
FileOpen $1 "$InstDir\Uninst.exe" a
FileSeek $1 0 END
FileWrite $1 "CUSTDATA:QA" ; special id
FileClose $1
SectionEnd
Function un.ReadCustomerData
# See http://nsis.sourceforge.net/ReadCustomerData
FunctionEnd
!include LogicLib.nsh
Section Uninstall
Push "CUSTDATA:"
Call un.ReadCustomerData
Pop $0
${If} $0 == "QA"
DeleteRegKey ...
${EndIf}
SectionEnd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.