${NSD_CreateCheckbox} 0 120 100% 30u "Don't use %APPDATA%$\nEnable this option to make Notepad++ load/write the configuration files from/to its install directory. Check it if you use Notepad++ in a USB device."
MessageBox MB_YESNO|MB_ICONSTOP "This version of Notepad++ doesn't support Windows XP. The installation will be aborted.$\n$\nDo you want to go to Notepad++ download page for downloading the last version which supports XP (v7.9.2)?" IDYES xp_openDlPage IDNO xp_goQuit
MessageBox MB_YESNO|MB_ICONSTOP "This version of Notepad++ doesn't support Windows Server 2003. The installation will be aborted.$\n$\nDo you want to go to Notepad++ download page for downloading the last version which supports this OS?" IDYES ws2003_openDlPage IDNO ws2003_goQuit
; we cannot run ARM64 binaries on a x86/x64 CPU (the other way around is possible - x86 on ARM64 CPU)
MessageBox MB_YESNO|MB_ICONSTOP "This installer contains ARM64 version of Notepad++ incompatible with your computer processor running, so the installation will be aborted.$\n$\nDo you want to go to the Notepad++ site to download a compatible (x86/x64) installer instead?" IDYES arm64_openDlPage IDNO arm64_goQuit
; to not influence the global NSIS vars used here, push them on the stack and pop them out at the end
Push $0 ; running process main HWND
Push $1 ; result of the waiting for the running process object
Push $2 ; running process HANDLE
Push $3 ; possible WIN32 error code (the GetLastError() result)
findRunningProcessByClassName:
FindWindow $0 '${RUNPROC_WND_CLASS}' ''
IntPtrCmp $0 0 processNotRunning
IsWindow $0 0 processNotRunning
IfSilent skipDetailPrint 0
DetailPrint "Closing the ${RUNPROC_WND_CLASS} app running..."
skipDetailPrint:
System::Call 'user32.dll::GetWindowThreadProcessId(i r0, *i .r1) i .r2'
System::Call 'kernel32.dll::OpenProcess(i ${RUNPROC_SYNC_TERM}, i 0, i r1) p .r2 ?e' ; ?e ... the NSIS system plugin will additionally put the GetLastError() code on top of the stack
pop $3 ; a possible WIN32 error code will be here
IntPtrCmp $2 0 openProcessFail
System::Call 'user32.dll::PostMessage(i $0, i ${WM_CLOSE}, i 0, i 0)'
System::Call 'kernel32.dll::WaitForSingleObject(i r2, i ${RUNPROC_WAIT_FOR_EXIT_MAX_MS}) i .r1'
IntCmp $1 0 closeProcessHandle ; 0 == WAIT_OBJECT_0 (signaled state of the process to close...)
; process could not be stopped by the usual WM_CLOSE way, so use a hard termination instead
IfSilent terminateProcess 0
MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "Installer cannot stop the running ${RUNPROC_WND_CLASS} by usual closing request.$\n$\nDo you want to forcefully terminate that process?" /SD IDYES IDYES terminateProcess IDNO closeProcessHandle
; cancel was selected, so close the opened running process handle and quit immediately
System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
SetErrorLevel 5 ; set an exit code > 0 otherwise the installer returns 0 aka SUCCESS (5 == ERROR_ACCESS_DENIED)
Quit ; installer will end
terminateProcess:
System::Call 'kernel32.dll::TerminateProcess(i r2, i 0) i .r1'
closeProcessHandle:
System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
goto findRunningProcessByClassName ; loop, we need to check for all the possible instances of the process running