Skip to content

Commit

Permalink
fix(nsis): NSIS uninstaller doesn't kill child processes
Browse files Browse the repository at this point in the history
Close #2516
  • Loading branch information
develar committed Mar 10, 2018
1 parent daf6f59 commit b6580d8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!include "getProcessInfo.nsh"
!include "nsProcess.nsh"

# http://nsis.sourceforge.net/Allow_only_one_installer_instance
!macro ALLOW_ONLY_ONE_INSTALLER_INSTANCE
Expand Down Expand Up @@ -27,27 +28,43 @@ Var pid
!macro CHECK_APP_RUNNING
${GetProcessInfo} 0 $pid $1 $2 $3 $4
${if} $3 != "${APP_EXECUTABLE_FILENAME}"
nsProcess::_FindProcess /NOUNLOAD "${APP_EXECUTABLE_FILENAME}"
Pop $R0
nsProcess::_Unload
${If} $R0 == 0
${if} ${isUpdated}
# allow app to exit without explicit kill
Sleep 100
${endIf}

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
${if} ${isUpdated}
# allow app to exit without explicit kill
Sleep 1000
Goto doStopProcess
${endIf}
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$(appRunning)" /SD IDOK IDOK doStopProcess
Quit

doStopProcess:
DetailPrint 'Closing running "${PRODUCT_NAME}"...'
ExecWait 'taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
${If} $R0 == 0
# to ensure that files are not "in-use"
Sleep 100
${else}

DetailPrint 'Closing running "${PRODUCT_NAME}"...'

# https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092
ExecWait 'taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
# to ensure that files are not "in-use"
Sleep 100

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
# wait to give a chance to exit gracefully
Sleep 1000
# do not use /t tree kill - app was killed softly already
ExecWait 'taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"' $R0
${If} $R0 != 0
DetailPrint 'Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).'
Sleep 2000
${endIf}
${endIf}
${endIf}
${endIf}

${nsProcess::Unload}
!macroend
28 changes: 28 additions & 0 deletions packages/electron-builder-lib/templates/nsis/include/nsProcess.nsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
!define nsProcess::FindProcess `!insertmacro nsProcess::FindProcess`

!macro nsProcess::FindProcess _FILE _ERR
nsProcess::_FindProcess /NOUNLOAD `${_FILE}`
Pop ${_ERR}
!macroend


!define nsProcess::KillProcess `!insertmacro nsProcess::KillProcess`

!macro nsProcess::KillProcess _FILE _ERR
nsProcess::_KillProcess /NOUNLOAD `${_FILE}`
Pop ${_ERR}
!macroend

!define nsProcess::CloseProcess `!insertmacro nsProcess::CloseProcess`

!macro nsProcess::CloseProcess _FILE _ERR
nsProcess::_CloseProcess /NOUNLOAD `${_FILE}`
Pop ${_ERR}
!macroend


!define nsProcess::Unload `!insertmacro nsProcess::Unload`

!macro nsProcess::Unload
nsProcess::_Unload
!macroend

0 comments on commit b6580d8

Please sign in to comment.