Skip to content

Commit

Permalink
fix(nsis): Ignore other users processes during per-user installation (#…
Browse files Browse the repository at this point in the history
…6472)

* fix(NSIS): ignore process owned by other users

Only find and kill processes owned by the current user on install.
On per-user installation, other users run their own copy of the app.
These instances will not block installation and should be left untouched.

Fixes #6104
  • Loading branch information
I-Otsuki committed Dec 6, 2021
1 parent f5c1e00 commit e3d06af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-elephants-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
---

fix(nsis): Ignore other users processes when installing for only current user
Closes #6104
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
!endif
!macroend

!macro FIND_PROCESS _FILE _ERR
!ifdef INSTALL_MODE_PER_ALL_USERS
${nsProcess::FindProcess} "${_FILE}" ${_ERR}
!else
# find process owned by current user
nsExec::Exec `cmd /c tasklist /FI "USERNAME eq %USERNAME%" /FI "IMAGENAME eq ${_FILE}" | find "${_FILE}"`
Pop ${_ERR}
!endif
!macroend

!macro _CHECK_APP_RUNNING
${GetProcessInfo} 0 $pid $1 $2 $3 $4
${if} $3 != "${APP_EXECUTABLE_FILENAME}"
Expand All @@ -43,7 +53,7 @@
Sleep 300
${endIf}

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
!insertmacro FIND_PROCESS "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
${if} ${isUpdated}
# allow app to exit without explicit kill
Expand All @@ -58,7 +68,11 @@
DetailPrint `Closing running "${PRODUCT_NAME}"...`

# https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092
nsExec::Exec `taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
!ifdef INSTALL_MODE_PER_ALL_USERS
nsExec::Exec `taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"`
!else
nsExec::Exec `cmd /c taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid" /fi "USERNAME eq %USERNAME%"`
!endif
# to ensure that files are not "in-use"
Sleep 300

Expand All @@ -68,13 +82,18 @@
loop:
IntOp $R1 $R1 + 1

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
!insertmacro FIND_PROCESS "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
# wait to give a chance to exit gracefully
Sleep 1000
nsExec::Exec `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).`
!ifdef INSTALL_MODE_PER_ALL_USERS
nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"`
!else
nsExec::Exec `cmd /c taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid" /fi "USERNAME eq %USERNAME%"`
!endif
!insertmacro FIND_PROCESS "${APP_EXECUTABLE_FILENAME}" $R0
${If} $R0 == 0
DetailPrint `Waiting for "${PRODUCT_NAME}" to close.`
Sleep 2000
${else}
Goto not_running
Expand Down

0 comments on commit e3d06af

Please sign in to comment.