Skip to content

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

panther7
Copy link
Contributor

@panther7 panther7 commented Apr 29, 2025

Modified the process termination logic in NSIS scripts to only kill application processes that are running from the installation directory. This prevents accidental termination of processes with the same name running from other locations during installation or update.

issue: #9009

EDIT: Actually works only on PowerShell Core (7+), because (default) powershell 5.1 is broken, because Get-Process returns empty Path for processes. #9069 (comment)

Copy link

changeset-bot bot commented Apr 29, 2025

🦋 Changeset detected

Latest commit: d82b90a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mmaietta
Copy link
Collaborator

@beyondkmp would you mind taking a look at this when you have a chance?

@mmaietta
Copy link
Collaborator

@panther7 following up here, what tests have you run so far?

Wondering if we can create an install+update test somehow for this in GHA runner? Similar to how this works: https://github.com/electron-userland/electron-builder/pull/9113/files?diff=unified&w=1#diff-1d9441830c74b56db3ecc46ef9805c4519141c15e145fabb24159d86e49d526dR10-R31

@mmaietta
Copy link
Collaborator

Working on a full "blackbox" test suite for verifying installation and updater flows with native/non-mocked Updaters
#9122

Will get that functional and then pull it into this PR for you so that we can add a black-box test for this

@panther7 panther7 force-pushed the nsis-kill-process branch from 523ac51 to c73d47a Compare June 6, 2025 09:37
@panther7 panther7 force-pushed the nsis-kill-process branch from c73d47a to e34c1c8 Compare June 17, 2025 14:29
@panther7 panther7 changed the title feat(nsis): terminate only processes running in installation folder DRAFT: feat(nsis): terminate only processes running in installation folder Jun 17, 2025
@panther7 panther7 force-pushed the nsis-kill-process branch from e34c1c8 to 309b2e5 Compare June 17, 2025 22:16
@panther7 panther7 changed the title DRAFT: feat(nsis): terminate only processes running in installation folder feat(nsis): terminate only processes running in installation folder Jun 17, 2025
@panther7
Copy link
Contributor Author

panther7 commented Jun 17, 2025

After hard testing, done.

BUT, only works on powershell 7+, because powershell 5 have "bug" and sometimes are Paths empty, which I need for detect right process.

Anyway, taskkill and tasklist are fallback.

@panther7 panther7 force-pushed the nsis-kill-process branch 2 times, most recently from 0540a91 to 77b294b Compare June 18, 2025 07:03
@panther7
Copy link
Contributor Author

I found solution for PowerShell 5+. It must be use Get-CimInstance -ClassName Win32_Process, because Get-Process inside instance 32bit PowerShell 5 don't view Paths for 64bit application. Get-CimInstance returns Paths for all processes, both 32bit and 64bit.

Check fixup.

@mmaietta
Copy link
Collaborator

Nice work @panther7 !! I need to do some hard testing on my side just to sanity check. Is there a way to force whether powershell or cmd approach is used for app termination?

Just disable powershell via policy?

!else
StrCpy $CmdPath "$SYSDIR\cmd.exe"
StrCpy $FindPath "$SYSDIR\find.exe"
StrCpy $PowerShellPath "$SYSDIR\WindowsPowerShell\v1.0\powershell.exe"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmaietta You can edit this to StrCpy $PowerShellPath "blablablaexe" if you want "disable" powershell.

Modified the process termination logic in NSIS scripts to only kill application
processes that are running from the installation directory. This prevents
accidental termination of processes with the same name running from other
locations during installation or update.
@panther7 panther7 force-pushed the nsis-kill-process branch from 6fb2de4 to d82b90a Compare June 24, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants