11!include " getProcessInfo.nsh"
2+ !include " nsProcess.nsh"
23
34# http://nsis.sourceforge.net/Allow_only_one_installer_instance
45!macro ALLOW_ONLY_ONE_INSTALLER_INSTANCE
@@ -27,27 +28,43 @@ Var pid
2728!macro CHECK_APP_RUNNING
2829 ${GetProcessInfo} 0 $pid $1 $2 $3 $4
2930 ${if} $3 != " ${APP_EXECUTABLE_FILENAME}"
30- nsProcess::_FindProcess /NOUNLOAD " ${APP_EXECUTABLE_FILENAME}"
31- Pop $R0
32- nsProcess::_Unload
33- ${If} $R0 == 0
31+ ${if} ${isUpdated}
32+ # allow app to exit without explicit kill
33+ Sleep 100
34+ ${endIf}
35+
36+ ${nsProcess::FindProcess } " ${APP_EXECUTABLE_FILENAME}" $R0
37+ ${if} $R0 == 0
3438 ${if} ${isUpdated}
3539 # allow app to exit without explicit kill
3640 Sleep 1000
3741 Goto doStopProcess
3842 ${endIf}
3943 MessageBox MB_OKCANCEL |MB_ICONEXCLAMATION " $(appRunning)" /SD IDOK IDOK doStopProcess
4044 Quit
45+
4146 doStopProcess:
42- DetailPrint ' Closing running "${PRODUCT_NAME}"...'
43- ExecWait ' taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
44- ${If} $R0 == 0
45- # to ensure that files are not "in-use"
46- Sleep 100
47- ${else}
47+
48+ DetailPrint ' Closing running "${PRODUCT_NAME}"...'
49+
50+ # https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092
51+ ExecWait ' taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
52+ # to ensure that files are not "in-use"
53+ Sleep 100
54+
55+ ${nsProcess::FindProcess } " ${APP_EXECUTABLE_FILENAME}" $R0
56+ ${if} $R0 == 0
57+ # wait to give a chance to exit gracefully
58+ Sleep 1000
59+ # do not use /t tree kill - app was killed softly already
60+ ExecWait ' taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
61+ ${If} $R0 != 0
4862 DetailPrint ' Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).'
4963 Sleep 2000
5064 ${endIf}
65+ ${endIf}
5166 ${endIf}
5267 ${endIf}
68+
69+ ${nsProcess::Unload }
5370!macroend
0 commit comments