Skip to content

Commit b6580d8

Browse files
committed
fix(nsis): NSIS uninstaller doesn't kill child processes
Close #2516
1 parent daf6f59 commit b6580d8

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

packages/electron-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!define nsProcess::FindProcess `!insertmacro nsProcess::FindProcess`
2+
3+
!macro nsProcess::FindProcess _FILE _ERR
4+
nsProcess::_FindProcess /NOUNLOAD `${_FILE}`
5+
Pop ${_ERR}
6+
!macroend
7+
8+
9+
!define nsProcess::KillProcess `!insertmacro nsProcess::KillProcess`
10+
11+
!macro nsProcess::KillProcess _FILE _ERR
12+
nsProcess::_KillProcess /NOUNLOAD `${_FILE}`
13+
Pop ${_ERR}
14+
!macroend
15+
16+
!define nsProcess::CloseProcess `!insertmacro nsProcess::CloseProcess`
17+
18+
!macro nsProcess::CloseProcess _FILE _ERR
19+
nsProcess::_CloseProcess /NOUNLOAD `${_FILE}`
20+
Pop ${_ERR}
21+
!macroend
22+
23+
24+
!define nsProcess::Unload `!insertmacro nsProcess::Unload`
25+
26+
!macro nsProcess::Unload
27+
nsProcess::_Unload
28+
!macroend

0 commit comments

Comments
 (0)