From 2a0db8b42e3047ca5f29f76ac4cb866879a0b090 Mon Sep 17 00:00:00 2001 From: anders_k Date: Tue, 16 Feb 2021 13:47:25 +0000 Subject: [PATCH] Handle app running git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7261 212acab6-be3b-0410-9dea-997c60f758d6 --- Examples/install-per-user.nsi | 19 ++++++++++++++----- Examples/install-shared.nsi | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Examples/install-per-user.nsi b/Examples/install-per-user.nsi index 9c31340e..f925ac1f 100644 --- a/Examples/install-per-user.nsi +++ b/Examples/install-per-user.nsi @@ -11,7 +11,7 @@ folders inside the users profile. */ -!define NAME "Per-User example" +!define NAME "Per-user example" !define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" Name "${NAME}" OutFile "Install ${NAME}.exe" @@ -48,6 +48,7 @@ Function un.onInit SetShellVarContext Current FunctionEnd + Section "Program files (Required)" SectionIn Ro @@ -161,12 +162,20 @@ Section -un.ShellAssoc ${NotifyShell_AssocChanged} SectionEnd -Section -Uninstall - ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" - Delete "$SMPrograms\${NAME}.lnk" +!macro DeleteFileOrAskAbort path + ClearErrors + Delete "${path}" + IfErrors 0 +3 + MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP 'Unable to delete "${path}"!' IDRETRY -3 IDIGNORE +2 + Abort "Aborted" +!macroend - Delete "$InstDir\MyApp.exe" +Section -Uninstall + !insertmacro DeleteFileOrAskAbort "$InstDir\MyApp.exe" Delete "$InstDir\Uninst.exe" RMDir "$InstDir" DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}" + + ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" + Delete "$SMPrograms\${NAME}.lnk" SectionEnd diff --git a/Examples/install-shared.nsi b/Examples/install-shared.nsi index 8149010b..01e1fe1d 100644 --- a/Examples/install-shared.nsi +++ b/Examples/install-shared.nsi @@ -24,12 +24,14 @@ InstallDirRegKey HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString" !include LogicLib.nsh !include Integration.nsh + Page Directory Page InstFiles Uninstpage UninstConfirm Uninstpage InstFiles + !macro EnsureAdminRights UserInfo::GetAccountType Pop $0 @@ -74,12 +76,20 @@ Section "Start Menu shortcut" SectionEnd -Section -Uninstall - ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" - Delete "$SMPrograms\${NAME}.lnk" +!macro DeleteFileOrAskAbort path + ClearErrors + Delete "${path}" + IfErrors 0 +3 + MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP 'Unable to delete "${path}"!' IDRETRY -3 IDIGNORE +2 + Abort "Aborted" +!macroend - Delete "$InstDir\MyApp.exe" +Section -Uninstall + !insertmacro DeleteFileOrAskAbort "$InstDir\MyApp.exe" Delete "$InstDir\Uninst.exe" RMDir "$InstDir" DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}" + + ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" + Delete "$SMPrograms\${NAME}.lnk" SectionEnd