Skip to content
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

Bug: NSIS Installer fails to check if app is running #7413

Closed
mkozonits opened this issue Feb 7, 2023 · 5 comments
Closed

Bug: NSIS Installer fails to check if app is running #7413

mkozonits opened this issue Feb 7, 2023 · 5 comments

Comments

@mkozonits
Copy link

mkozonits commented Feb 7, 2023

Which version of electron-builder are you using?

  • 23.6.0:

Which version of node are you using?

  • 14.17.3:

Which version of electron are you using?

  • 20.0.2:
  • not electron related:

For which target are you building for?

  • Windows 10 x64:

The issue occurs with the following config for NSIS installer:

  • perMachine = false

Before the NSIS Installer/Uninstaller does any modifications, it will check, if the app is currently running. After this change #6472 the installer will only check for running app with the same user (which is currently logged in), not for the whole system.

image

This line of code checks for running app with "tasklist" and then filtering with "find" in case there is some unexpected output or an error.
Here comes the problem: If the name of the .exe file is too long, it will get cut off by windows with the "tasklist" command. If that is the case, "find" will not find the whole app .exe name anymore, and therefore assumes, that no app is currently running.

Here I attach an picuture of an example why this "find" breaks the logic:

image

@mkozonits mkozonits changed the title NSIS Installer fails to check if app is running Bug: NSIS Installer fails to check if app is running Feb 7, 2023
@mmaietta
Copy link
Collaborator

Nice find, that's quite some odd behavior.
What's a good alternative to use then?

@mkozonits
Copy link
Author

This would be possible https://stackoverflow.com/a/56577365
or there is also a option to output in tasklist in csv to have the full name, I don't know which one is the best for our case

@mmaietta
Copy link
Collaborator

Great callout for using csv output, that worked locally in my powershell.

I've created this patch via patch-package as a potential test
app-builder-lib+23.0.3.patch

diff --git a/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh b/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
index cc77993..41681dc 100644
--- a/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
+++ b/node_modules/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh
@@ -40,8 +40,9 @@
     ${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}"`
+    nsExec::Exec `cmd /c tasklist /FI "USERNAME eq %USERNAME%" /FI "IMAGENAME eq ${_FILE}" -fo csv | convertfrom-csv`
     Pop ${_ERR}
+    Pop $1.PID
   !endif
 !macroend
 

Honestly, I have no idea if Pop $1.PID is the correct syntax. I've tested locally just convertfrom-csv and it works locally in powershell for IMAGENAMEs that are longer than tasklist can output. So also any knowledge on how to handle nsExec in macros, I'd really appreciate some guidance.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Apr 14, 2023
@github-actions
Copy link
Contributor

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants