-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nsis): terminate only processes running in installation folder #9069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
panther7
wants to merge
1
commit into
electron-userland:master
Choose a base branch
from
panther7:nsis-kill-process
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"app-builder-lib": patch | ||
--- | ||
|
||
feat(nsis): terminate only processes running in installation folder | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,22 +30,77 @@ | |
!macroend | ||
|
||
!macro CHECK_APP_RUNNING | ||
!ifmacrodef customCheckAppRunning | ||
!insertmacro customCheckAppRunning | ||
Var /GLOBAL CmdPath | ||
Var /GLOBAL FindPath | ||
Var /GLOBAL PowerShellPath | ||
!ifmacrodef customCheckAppRunning | ||
!insertmacro customCheckAppRunning | ||
!else | ||
StrCpy $CmdPath "$SYSDIR\cmd.exe" | ||
StrCpy $FindPath "$SYSDIR\find.exe" | ||
StrCpy $PowerShellPath "$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmaietta You can edit this to |
||
!insertmacro IS_POWERSHELL_AVAILABLE | ||
!insertmacro _CHECK_APP_RUNNING | ||
!endif | ||
!macroend | ||
|
||
!macro IS_POWERSHELL_AVAILABLE | ||
Var /GLOBAL IsPowerShellAvailable ; 0 = available, 1 = not available | ||
# Try running PowerShell with a simple command to check if it's available | ||
nsExec::Exec `"$PowerShellPath" -C "if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"` | ||
Pop $0 # Return code (0 = success, other = error) | ||
|
||
${if} $0 == 0 | ||
# PowerShell is available, check if it's not blocked by policies | ||
nsExec::Exec `"$PowerShellPath" -C "if ((Get-ExecutionPolicy -Scope Process) -eq 'Restricted') { exit 1 } else { exit 0 }"` | ||
Pop $0 | ||
${endIf} | ||
|
||
${if} $0 != 0 | ||
StrCpy $0 1 | ||
${endIf} | ||
|
||
StrCpy $IsPowerShellAvailable $0 | ||
!macroend | ||
|
||
!macro FIND_PROCESS _FILE _RETURN | ||
${if} $IsPowerShellAvailable == 0 | ||
nsExec::Exec `"$PowerShellPath" -C "if ((Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')}).Count -gt 0) { exit 0 } else { exit 1 }"` | ||
Pop ${_RETURN} | ||
${else} | ||
!ifdef INSTALL_MODE_PER_ALL_USERS | ||
${nsProcess::FindProcess} "${_FILE}" ${_RETURN} | ||
!else | ||
!insertmacro _CHECK_APP_RUNNING | ||
# find process owned by current user | ||
nsExec::Exec `"$CmdPath" /C tasklist /FI "USERNAME eq %USERNAME%" /FI "IMAGENAME eq ${_FILE}" /FO CSV | "$FindPath" "${_FILE}"` | ||
Pop ${_RETURN} | ||
!endif | ||
${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 `"$SYSDIR\cmd.exe" /c tasklist /FI "USERNAME eq %USERNAME%" /FI "IMAGENAME eq ${_FILE}" /FO csv | "$SYSDIR\find.exe" "${_FILE}"` | ||
Pop ${_ERR} | ||
!endif | ||
!macroend | ||
!macro KILL_PROCESS _FILE _FORCE | ||
Push $0 | ||
${if} ${_FORCE} == 1 | ||
${if} $IsPowerShellAvailable == 0 | ||
StrCpy $0 "-Force" | ||
${else} | ||
StrCpy $0 "/F" | ||
${endIf} | ||
${else} | ||
StrCpy $0 "" | ||
${endIf} | ||
|
||
${if} $IsPowerShellAvailable == 0 | ||
nsExec::Exec `"$PowerShellPath" -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')} | % { Stop-Process -Id $$_.ProcessId $0 }"` | ||
${else} | ||
!ifdef INSTALL_MODE_PER_ALL_USERS | ||
nsExec::Exec `taskkill /IM "${_FILE}" /FI "PID ne $pid"` | ||
!else | ||
nsExec::Exec `"$CmdPath" /C taskkill $0 /IM "${_FILE}" /FI "PID ne $pid" /FI "USERNAME eq %USERNAME%"` | ||
!endif | ||
${endIf} | ||
Pop $0 | ||
!macroend | ||
|
||
!macro _CHECK_APP_RUNNING | ||
${GetProcessInfo} 0 $pid $1 $2 $3 $4 | ||
|
@@ -69,12 +124,7 @@ | |
|
||
DetailPrint `Closing running "${PRODUCT_NAME}"...` | ||
|
||
# https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092 | ||
!ifdef INSTALL_MODE_PER_ALL_USERS | ||
nsExec::Exec `taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` | ||
!else | ||
nsExec::Exec `"$SYSDIR\cmd.exe" /c taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid" /fi "USERNAME eq %USERNAME%"` | ||
!endif | ||
!insertmacro KILL_PROCESS "${APP_EXECUTABLE_FILENAME}" 0 | ||
# to ensure that files are not "in-use" | ||
Sleep 300 | ||
|
||
|
@@ -88,13 +138,9 @@ | |
${if} $R0 == 0 | ||
# wait to give a chance to exit gracefully | ||
Sleep 1000 | ||
!ifdef INSTALL_MODE_PER_ALL_USERS | ||
nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` | ||
!else | ||
nsExec::Exec `"$SYSDIR\cmd.exe" /c taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid" /fi "USERNAME eq %USERNAME%"` | ||
!endif | ||
!insertmacro KILL_PROCESS "${APP_EXECUTABLE_FILENAME}" 1 # 1 = force kill | ||
!insertmacro FIND_PROCESS "${APP_EXECUTABLE_FILENAME}" $R0 | ||
${If} $R0 == 0 | ||
${if} $R0 == 0 | ||
DetailPrint `Waiting for "${PRODUCT_NAME}" to close.` | ||
Sleep 2000 | ||
${else} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.