From 5c80be7667eb84f0345ef827cab030724c2e13c6 Mon Sep 17 00:00:00 2001 From: xomx Date: Fri, 20 Oct 2023 15:45:15 +0200 Subject: [PATCH] Fix silent installer mode when Notepad++ is running issue When Notepad++ installer with the '/S' optional param is used while a previously installed Notepad++ instance is running, it does not update the locked main 'notepad++.exe' binary, but the installer still reports success (exit code == 0, regkeys actualized according to the installer version used...). Moreover - because the installation/upgrade then looks like it is done, some automatic update services like winget cannot be used until a next N++ version is released (winget erroneously reports that the current version is already installed...). The fix consist to set error code and quit installer, when installer in silent mode, and there's an instance of Notepad++ open. Fix #10189, fix #10277, fix #22514, fix #14236, fix partially #8514, close #14251 --- PowerEditor/installer/nppSetup.nsi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PowerEditor/installer/nppSetup.nsi b/PowerEditor/installer/nppSetup.nsi index 36a001531..97e1a33ad 100644 --- a/PowerEditor/installer/nppSetup.nsi +++ b/PowerEditor/installer/nppSetup.nsi @@ -150,6 +150,16 @@ Function .onInit ; ; --- PATCH END --- + ; handle the possible Silent Mode (/S) & already running Notepad++ (without this an incorrect partial installation is possible) + IfSilent 0 notInSilentMode + System::Call 'kernel32::OpenMutex(i 0x100000, b 0, t "nppInstance") i .R0' + IntCmp $R0 0 nppNotRunning + System::Call 'kernel32::CloseHandle(i $R0)' ; a Notepad++ instance is running, tidy-up the opened mutex handle only + SetErrorLevel 5 ; set an exit code > 0 otherwise the installer returns 0 aka SUCCESS ('5' means here the future ERROR_ACCESS_DENIED when trying to overwrite the notepad++.exe file...) + Quit ; silent installation is silent, currently we cannot continue without a user interaction (TODO: a new "/closeRunningNppAutomatically" installer optional param...) +nppNotRunning: +notInSilentMode: + ${GetParameters} $R0 ${GetOptions} $R0 "/noUpdater" $R1 ;case insensitive IfErrors withUpdater withoutUpdater